Comments (7)
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.
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.
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.
Added an issue specifically for point 1 here: #34
from cute_headers.
Closing this. Came up with a good way to support this in a new wrapper header for tinysound.
from cute_headers.
@RandyGaul Has this wrapper header been released?
from cute_headers.
@hsdk123 Not yet! :)
from cute_headers.
Related Issues (20)
- cute_aseprite: 1.3 Tilemap Support HOT 2
- [cute_sound.h v2.x] Support multiple contexts. HOT 2
- http://randygaul.net is taken over by squatters HOT 1
- cute_net.h times out over the internet HOT 5
- Dynamically set panning for an individual playing sound HOT 2
- cute_aseprite.h - v1.3 Tilesets Discussion HOT 4
- cute_aseprite.h - Aseprite v1.3 property map support
- Cute_tiled "staggered" causes warning HOT 1
- inclusion of infinite maps and chunks HOT 3
- c2TOI returning wrong contact point
- cute_tls - allow ignoring certificate errors HOT 1
- cute_tiled: Force loading RGBA for tintedcolor
- cute_tiled: object `type` field HOT 4
- cute_2d c2PolytoPolyManifold issue HOT 2
- [Cute_Net.h] Knowing if a packet has been sent. HOT 3
- [cute_tiled_h]: Field `name` points to wrong memory address. HOT 2
- cute_aseprite.h "warning C4456: declaration of 'frame' hides previous local declaration"
- Usage of c2x and rotation HOT 1
- cute_aseprite.h crash with both 9-slice and pivot enabled. HOT 1
- cute_sound 2.x has no equivalent of 1.x cs_stop_sound
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cute_headers.