diff --git a/src/sound/backend/i_sound.cpp b/src/sound/backend/i_sound.cpp index b593fee3f8..4bdc00b7e3 100644 --- a/src/sound/backend/i_sound.cpp +++ b/src/sound/backend/i_sound.cpp @@ -172,10 +172,6 @@ public: { return NULL; } - SoundStream *OpenStream (FileReader &reader, int flags) - { - return NULL; - } // Starts a sound. FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) diff --git a/src/sound/backend/i_sound.h b/src/sound/backend/i_sound.h index 775d47a3c8..bd10b11f75 100644 --- a/src/sound/backend/i_sound.h +++ b/src/sound/backend/i_sound.h @@ -76,7 +76,6 @@ public: virtual void Stop() = 0; virtual void SetVolume(float volume) = 0; virtual bool SetPaused(bool paused) = 0; - virtual unsigned int GetPosition() = 0; virtual bool IsEnded() = 0; virtual FString GetStats(); }; @@ -117,8 +116,7 @@ public: // Streaming sounds. virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0; - virtual SoundStream *OpenStream (FileReader &reader, int flags) = 0; - + // Starts a sound. virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0; virtual FISoundChannel *StartSound3D (SoundHandle sfx, SoundListener *listener, float vol, FRolloffInfo *rolloff, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, int channum, int chanflags, FISoundChannel *reuse_chan) = 0; diff --git a/src/sound/backend/oalsound.cpp b/src/sound/backend/oalsound.cpp index 39674b9a98..55df4b9820 100644 --- a/src/sound/backend/oalsound.cpp +++ b/src/sound/backend/oalsound.cpp @@ -232,25 +232,6 @@ class OpenALSoundStream : public SoundStream bool Looping; ALfloat Volume; - - SoundDecoder *Decoder; - static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user) - { - OpenALSoundStream *self = static_cast(_sstream); - if(length < 0) return false; - - size_t got = self->Decoder->read((char*)ptr, length); - if(got < (unsigned int)length) - { - if(!self->Looping || !self->Decoder->seek(0, false, true)) - return false; - got += self->Decoder->read((char*)ptr+got, length-got); - } - - return (got == (unsigned int)length); - } - - bool SetupSource() { /* Get a source, killing the farthest, lowest-priority sound if needed */ @@ -294,7 +275,7 @@ class OpenALSoundStream : public SoundStream public: OpenALSoundStream(OpenALSoundRenderer *renderer) - : Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f), Decoder(NULL) + : Renderer(renderer), Source(0), Playing(false), Looping(false), Volume(1.0f) { memset(Buffers, 0, sizeof(Buffers)); Renderer->AddStream(this); @@ -319,8 +300,6 @@ public: memset(Buffers, 0, sizeof(Buffers)); } getALError(); - - delete Decoder; } @@ -390,46 +369,6 @@ public: return (getALError()==AL_NO_ERROR); } - virtual bool SetPosition(unsigned int ms_pos) - { - std::unique_lock lock(Renderer->StreamLock); - if(!Decoder->seek(ms_pos, true, false)) - return false; - - if(!Playing.load()) - return true; - // Stop the source so that all buffers become processed, which will - // allow the next update to restart the source queue with the new - // position. - alSourceStop(Source); - getALError(); - lock.unlock(); - Renderer->StreamWake.notify_all(); - return true; - } - - virtual unsigned int GetPosition() - { - std::unique_lock lock(Renderer->StreamLock); - ALint offset, queued, state; - alGetSourcei(Source, AL_SAMPLE_OFFSET, &offset); - alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued); - alGetSourcei(Source, AL_SOURCE_STATE, &state); - if(getALError() != AL_NO_ERROR) - return 0; - - size_t pos = Decoder->getSampleOffset(); - lock.unlock(); - - if(state != AL_STOPPED) - { - size_t rem = queued*(Data.Size()/FrameSize) - offset; - if(pos > rem) pos -= rem; - else pos = 0; - } - return (unsigned int)(pos * 1000.0 / SampleRate); - } - virtual bool IsEnded() { return !Playing.load(); @@ -460,34 +399,11 @@ public: return stats; } - if (Decoder != nullptr) - { - pos = Decoder->getSampleOffset(); - len = Decoder->getSampleLength(); - } lock.unlock(); stats = (state == AL_INITIAL) ? "Buffering" : (state == AL_STOPPED) ? "Underrun" : (state == AL_PLAYING || state == AL_PAUSED) ? "Ready" : "Unknown state"; - if (Decoder != nullptr) - { - if (state == AL_STOPPED) - offset = BufferCount * (Data.Size() / FrameSize); - else - { - size_t rem = queued*(Data.Size() / FrameSize) - offset; - if (pos > rem) pos -= rem; - else if (len > 0) pos += len - rem; - else pos = 0; - } - pos = (size_t)(pos * 1000.0 / SampleRate); - len = (size_t)(len * 1000.0 / SampleRate); - stats.AppendFormat(",%3u%% buffered", 100 - 100 * offset / (BufferCount*(Data.Size() / FrameSize))); - stats.AppendFormat(", %zu.%03zu", pos / 1000, pos % 1000); - if (len > 0) - stats.AppendFormat(" / %zu.%03zu", len / 1000, len % 1000); - } if(state == AL_PAUSED) stats += ", paused"; if(state == AL_PLAYING) @@ -607,60 +523,6 @@ public: return true; } - bool Init(FileReader &reader, bool loop) - { - if(!SetupSource()) - { - return false; - } - - if(Decoder) delete Decoder; - auto mreader = new FileReaderMusicInterface(reader); - Decoder = SoundDecoder::CreateDecoder(mreader); - if (!Decoder) - { - mreader->close(); - return false; - } - - Callback = DecoderCallback; - UserData = NULL; - Format = AL_NONE; - FrameSize = 1; - - ChannelConfig chans; - SampleType type; - int srate; - - Decoder->getInfo(&srate, &chans, &type); - if(chans == ChannelConfig_Mono) - { - if(type == SampleType_UInt8) Format = AL_FORMAT_MONO8; - if(type == SampleType_Int16) Format = AL_FORMAT_MONO16; - FrameSize *= 1; - } - if(chans == ChannelConfig_Stereo) - { - if(type == SampleType_UInt8) Format = AL_FORMAT_STEREO8; - if(type == SampleType_Int16) Format = AL_FORMAT_STEREO16; - FrameSize *= 2; - } - if(type == SampleType_UInt8) FrameSize *= 1; - if(type == SampleType_Int16) FrameSize *= 2; - - if(Format == AL_NONE) - { - Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans), - GetSampleTypeName(type)); - return false; - } - SampleRate = srate; - Looping = loop; - - Data.Resize((SampleRate / 5) * FrameSize); - - return true; - } }; @@ -1547,19 +1409,6 @@ SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int return stream; } -SoundStream *OpenALSoundRenderer::OpenStream(FileReader &reader, int flags) -{ - if(StreamThread.get_id() == std::thread::id()) - StreamThread = std::thread(std::mem_fn(&OpenALSoundRenderer::BackgroundProc), this); - OpenALSoundStream *stream = new OpenALSoundStream(this); - if (!stream->Init(reader, !!(flags&SoundStream::Loop))) - { - delete stream; - return NULL; - } - return stream; -} - FISoundChannel *OpenALSoundRenderer::StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) { if(FreeSfx.Size() == 0) diff --git a/src/sound/backend/oalsound.h b/src/sound/backend/oalsound.h index 2b1a50fd4a..c4b17e2e89 100644 --- a/src/sound/backend/oalsound.h +++ b/src/sound/backend/oalsound.h @@ -135,7 +135,6 @@ public: // Streaming sounds. virtual SoundStream *CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata); - virtual SoundStream *OpenStream(FileReader &reader, int flags); // Starts a sound. virtual FISoundChannel *StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan);