Git Product home page Git Product logo

Comments (7)

ddengster avatar ddengster commented on May 3, 2024 1

Some clarification: my game loads OGG files already(some of them 3-5mb a piece, total ~200 files), I preferably want to load music on demand and not at the initialization stage, because I can have quite a number of those and don't see the need to keep them in memory when I'm not using them. When I load OGG files during the game using tinysound, I get a frame spike of 0.5 to 1 second due to the loading; which is really bad for games. And on top of that I have other things to do during my game's initialization; this is not like graphics shaders where you can get away with loading 50 compiled shaders at the start of your game because they're so small in number and in memory for the game's lifetime.

Anyway, it's up to you, but for me this streaming feature is crucial for my game, at least for OGG files.

For others, here's some code for as to how oggstream&openal can be used to stream data. I suppose you could have something in tinysound that does what alBufferData/alSourceQueueBuffers does.

`
#define AUDIO_SAMPLE_COUNT 1024 * 32
ALshort data[AUDIO_SAMPLE_COUNT] = { 0 };

uint samples_read_per_channel = stb_vorbis_get_samples_short_interleaved(stream->mOggStream,
stream->mInfo.channels, data, AUDIO_SAMPLE_COUNT);
uint samples_read = samples_read_per_channel * stream->mInfo.channels;
stream->mRemainingUnreadSamples -= samples_read;

if (stream->mLoop && stream->mOggStream->eof)
{
uint totalsamples = stb_vorbis_stream_length_in_samples(stream->mOggStream) * stream->mInfo.channels;
ALshort* dataoffset = data + samples_read;
while (samples_read < AUDIO_SAMPLE_COUNT)
{
//repeat fill the buffer so long as buffer has space
stb_vorbis_seek_start(stream->mOggStream);

  uint samples_to_fill = AUDIO_SAMPLE_COUNT - samples_read;
  samples_read_per_channel = stb_vorbis_get_samples_short_interleaved(stream->mOggStream,
    stream->mInfo.channels, dataoffset, samples_to_fill);

  uint samples_readthisloop = samples_read_per_channel * stream->mInfo.channels;
  dataoffset += samples_readthisloop;
  samples_read += samples_readthisloop;

  stream->mRemainingUnreadSamples = totalsamples - samples_readthisloop;
} 
samples_read = AUDIO_SAMPLE_COUNT;

}

alBufferData(buffer, stream->mFormat, data, samples_read * sizeof(ALshort), stream->mInfo.sample_rate);
alSourceQueueBuffers(stream->mSource, 2, stream->mBuffers);
`

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Thanks for the post. Good suggestion on number 3!

For point 2: Use the high level API instead. The low level API is specifically made for people that want complete control over the memory usage, which implies that you'll have to take care of freeing memory when sounds aren't playing manually.

Also pretty sure if using the high level API, if a sound's audio is free'd the associated playing instances will deref the free'd memory and crash. I'll think about adding in a mechanism to catch that automatically. Pretty sure I can get in a feature for this within the week.

For point 1: OGG support done via stb_vorbis, which already has its own streaming API (more info here). Hooking up some code into tinysound to handle streaming would be a great feature to add. I haven't added it yet as I personally haven't needed it. However, since you're now the second person to bring this point up it seems fairly important. I think a separate issue for this feature request sounds reasonable. Streaming audio is pretty low on my own priority list for my personal projects, so it would be greatly appreciated if someone took the time to try their hand at a pull request.

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Hmm. I'm not really sold on the idea of streaming in WAV files.

If a WAV file is causing a load time problem, then why not store it compressed as OGG, and load it in earlier? And at that point it can use the OGG streaming API from stb_vorbis.

In this way it seems like writing a streaming service for WAV files would be moot.

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Added an issue specifically for point 1 here: #34

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Closing this. Came up with a good way to support this in a new wrapper header for tinysound.

from cute_headers.

hsdk123 avatar hsdk123 commented on May 3, 2024

@RandyGaul Has this wrapper header been released?

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

@hsdk123 Not yet! :)

from cute_headers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.