Decode ogg/vorbis from memory or file path.
30 using uchar =
unsigned char;
31 using ushort =
unsigned short;
37 vorbis = stb_vorbis_open_filename(path, &error,
nullptr);
42 vorbis = stb_vorbis_open_memory(
43 reinterpret_cast<const unsigned char*
>(path), length, &error,
nullptr
47 if (error != VORBIS__no_error) {
48 stb_vorbis_close(vorbis);
52 const stb_vorbis_info info = stb_vorbis_get_info(vorbis);
53 const Size streamLength = stb_vorbis_stream_length_in_samples(vorbis);
56 out.sampleRate = info.sample_rate;
57 out.resize(streamLength,
Size(info.channels));
59 if (std::is_same<float, T>::value) {
60 HeapBuffer<T*> buffer;
61 buffer.resize(info.channels);
62 out.getRaw(buffer.data());
64 float** fbuf =
reinterpret_cast<float**
>(buffer.data());
65 Size got = stb_vorbis_get_samples_float(
66 vorbis, info.channels, fbuf, streamLength
68 out.setValidSize(got);
69 stb_vorbis_close(vorbis);
70 return got == streamLength;
75 int channels = info.channels;
76 float** bufferPtr =
nullptr;
77 while (read < streamLength) {
78 Size got = stb_vorbis_get_frame_float(vorbis, &channels, &bufferPtr);
79 out.set(bufferPtr, got, channels, 0, read);
83 out.setValidSize(read);
85 stb_vorbis_close(vorbis);
unsigned int Size
How the elements are addressed in the heapbuffer.