diff options
| author | Crystalwarrior <varsash@gmail.com> | 2019-10-04 14:41:33 +0300 |
|---|---|---|
| committer | Crystalwarrior <varsash@gmail.com> | 2019-10-04 14:41:33 +0300 |
| commit | 65332f209c9344e1d3f643ebca32a23dd6f31bdf (patch) | |
| tree | 19de340358b22173c2e19c2e061d8130ba926a7b /src/aomusicplayer.cpp | |
| parent | 9451822e0929643f638b3c79d4fd646df98b567a (diff) | |
fucking hell it's not accurate and doesn't match the absolute quality when it's played back in audacity jesus christ will the torture ever end
Diffstat (limited to 'src/aomusicplayer.cpp')
| -rw-r--r-- | src/aomusicplayer.cpp | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index b44e2e27..8fe6d15d 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -21,24 +21,6 @@ void AOMusicPlayer::play(QString p_song, int channel, bool crossfade) if (channel < 0) //wtf? return; QString f_path = ao_app->get_music_path(p_song); -// QString d_path = f_path + ".txt"; - -// if (file_exists(d_path)) //Contains loop/etc. information file -// { -// QStringList lines = ao_app->read_file(d_path).split("\n"); -// foreach (QString line, lines) -// { -// QStringList args = line.split("="); -// if (args.size() < 2) -// continue; -// QString arg = args[0].trimmed(); -// if (arg == "loop_start") -// loop_start = args[1].trimmed().toUInt(); -// else if (arg == "loop_end") -// loop_end = args[1].trimmed().toUInt(); -// } -// qDebug() << "Found data file for song" << p_song << loop_start << loop_end; -// } unsigned int flags = BASS_STREAM_PRESCAN | BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE; if (m_looping) @@ -48,6 +30,34 @@ void AOMusicPlayer::play(QString p_song, int channel, bool crossfade) if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(m_stream_list[channel], BASS_GetDevice()); + QString d_path = f_path + ".txt"; + + loop_start = 0; + loop_end = 0; + if (m_looping && file_exists(d_path)) //Contains loop/etc. information file + { + QStringList lines = ao_app->read_file(d_path).split("\n"); + foreach (QString line, lines) + { + QStringList args = line.split("="); + if (args.size() < 2) + continue; + QString arg = args[0].trimmed(); + + float sample_rate; + BASS_ChannelGetAttribute(newstream, BASS_ATTRIB_FREQ, &sample_rate); + qDebug() << sample_rate << args[1].trimmed(); + + if (arg == "loop_start") + loop_start = BASS_ChannelSeconds2Bytes(newstream, args[1].trimmed().toDouble() / static_cast<double>(sample_rate)); + else if (arg == "loop_length") + loop_end = loop_start + BASS_ChannelSeconds2Bytes(newstream, args[1].trimmed().toDouble() / static_cast<double>(sample_rate)); + else if (arg == "loop_end") + loop_end = BASS_ChannelSeconds2Bytes(newstream, args[1].trimmed().toDouble() / static_cast<double>(sample_rate)); + } + qDebug() << "Found data file for song" << p_song << "length" << BASS_ChannelGetLength(newstream, BASS_POS_BYTE) << "loop start" << loop_start << "loop end" << loop_end; + } + if (crossfade) { DWORD oldstream = m_stream_list[channel]; @@ -103,28 +113,32 @@ void AOMusicPlayer::set_volume(int p_value, int channel) } } -//void CALLBACK loopProc(HSYNC handle, DWORD channel, DWORD data, void *user) -//{ -// AOMusicPlayer *self= static_cast<AOMusicPlayer*>(user); -// qDebug() << BASS_ChannelGetPosition(channel, BASS_POS_BYTE); -// BASS_ChannelSetPosition(channel, self->loop_start, BASS_POS_BYTE); -//} +void CALLBACK loopProc(HSYNC handle, DWORD channel, DWORD data, void *user) +{ + AOMusicPlayer *self= static_cast<AOMusicPlayer*>(user); + qDebug() << BASS_ChannelGetPosition(channel, BASS_POS_BYTE); + BASS_ChannelSetPosition(channel, self->loop_start, BASS_POS_BYTE); +} void AOMusicPlayer::set_looping(bool toggle, int channel) { m_looping = toggle; - if (BASS_ChannelFlags(m_stream_list[channel], 0, 0) & BASS_SAMPLE_LOOP) + qDebug() << "looping" << m_looping; + if (m_looping == false && BASS_ChannelFlags(m_stream_list[channel], 0, 0) & BASS_SAMPLE_LOOP) { - if (m_looping == false) - BASS_ChannelFlags(m_stream_list[channel], 0, BASS_SAMPLE_LOOP); // remove the LOOP flag -// BASS_ChannelRemoveSync(m_stream_list[channel], loop_sync); + BASS_ChannelFlags(m_stream_list[channel], 0, BASS_SAMPLE_LOOP); // remove the LOOP flag + BASS_ChannelRemoveSync(m_stream_list[channel], loop_sync[channel]); } - else + else if (m_looping == true) { - if (m_looping == true) - BASS_ChannelFlags(m_stream_list[channel], BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set the LOOP flag -// if (loop_end > 0 && loop_end < BASS_ChannelGetLength(m_stream_list[channel], BASS_POS_BYTE)) -// loop_sync = BASS_ChannelSetSync(m_stream_list[channel], BASS_SYNC_POS | BASS_SYNC_MIXTIME, loop_end, loopProc, this); + BASS_ChannelFlags(m_stream_list[channel], BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set the LOOP flag + BASS_ChannelRemoveSync(m_stream_list[channel], loop_sync[channel]); + qDebug() << loop_end; + if (loop_end > 0) + { + loop_sync[channel] = BASS_ChannelSetSync(m_stream_list[channel], BASS_SYNC_POS | BASS_SYNC_MIXTIME, loop_end, loopProc, this); + qDebug() << "Started loop sync"; + } } } #elif defined(QTAUDIO) |
