Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
6d9379f6
Commit
6d9379f6
authored
Mar 17, 2023
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try getting sample exact seeking working with stb_vorbis.
parent
a8682c36
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
86 deletions
+108
-86
miniaudio.h
miniaudio.h
+108
-86
No files found.
miniaudio.h
View file @
6d9379f6
...
@@ -62675,34 +62675,10 @@ static ma_result ma_stbvorbis_post_init(ma_stbvorbis* pVorbis)
...
@@ -62675,34 +62675,10 @@ static ma_result ma_stbvorbis_post_init(ma_stbvorbis* pVorbis)
return MA_SUCCESS;
return MA_SUCCESS;
}
}
#endif
MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks,
ma_stbvorbis* pVorbis)
static ma_result ma_stbvorbis_init_internal_decoder_push(
ma_stbvorbis* pVorbis)
{
{
ma_result result;
ma_result result;
result = ma_stbvorbis_init_internal(pConfig, pVorbis);
if (result != MA_SUCCESS) {
return result;
}
if (onRead == NULL || onSeek == NULL) {
return MA_INVALID_ARGS; /* onRead and onSeek are mandatory. */
}
pVorbis->onRead = onRead;
pVorbis->onSeek = onSeek;
pVorbis->onTell = onTell;
pVorbis->pReadSeekTellUserData = pReadSeekTellUserData;
ma_allocation_callbacks_init_copy(&pVorbis->allocationCallbacks, pAllocationCallbacks);
#if !defined(MA_NO_VORBIS)
{
/*
stb_vorbis lacks a callback based API for it's pulling API which means we're stuck with the
pushing API. In order for us to be able to successfully initialize the decoder we need to
supply it with enough data. We need to keep loading data until we have enough.
*/
stb_vorbis* stb;
stb_vorbis* stb;
size_t dataSize = 0;
size_t dataSize = 0;
size_t dataCapacity = 0;
size_t dataCapacity = 0;
...
@@ -62716,9 +62692,9 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
...
@@ -62716,9 +62692,9 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
/* Allocate memory for the new chunk. */
/* Allocate memory for the new chunk. */
dataCapacity += MA_VORBIS_DATA_CHUNK_SIZE;
dataCapacity += MA_VORBIS_DATA_CHUNK_SIZE;
pNewData = (ma_uint8*)ma_realloc(pData, dataCapacity, pA
llocationCallbacks);
pNewData = (ma_uint8*)ma_realloc(pData, dataCapacity, &pVorbis->a
llocationCallbacks);
if (pNewData == NULL) {
if (pNewData == NULL) {
ma_free(pData, pA
llocationCallbacks);
ma_free(pData, &pVorbis->a
llocationCallbacks);
return MA_OUT_OF_MEMORY;
return MA_OUT_OF_MEMORY;
}
}
...
@@ -62729,13 +62705,13 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
...
@@ -62729,13 +62705,13 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
dataSize += bytesRead;
dataSize += bytesRead;
if (result != MA_SUCCESS) {
if (result != MA_SUCCESS) {
ma_free(pData, pA
llocationCallbacks);
ma_free(pData, &pVorbis->a
llocationCallbacks);
return result;
return result;
}
}
/* We have a maximum of 31 bits with stb_vorbis. */
/* We have a maximum of 31 bits with stb_vorbis. */
if (dataSize > INT_MAX) {
if (dataSize > INT_MAX) {
ma_free(pData, pA
llocationCallbacks);
ma_free(pData, &pVorbis->a
llocationCallbacks);
return MA_TOO_BIG;
return MA_TOO_BIG;
}
}
...
@@ -62760,7 +62736,7 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
...
@@ -62760,7 +62736,7 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
if (vorbisError == VORBIS_need_more_data) {
if (vorbisError == VORBIS_need_more_data) {
continue;
continue;
} else {
} else {
ma_free(pData, pA
llocationCallbacks);
ma_free(pData, &pVorbis->a
llocationCallbacks);
return MA_ERROR; /* Failed to open the stb_vorbis decoder. */
return MA_ERROR; /* Failed to open the stb_vorbis decoder. */
}
}
}
}
...
@@ -62772,12 +62748,47 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
...
@@ -62772,12 +62748,47 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
pVorbis->push.dataSize = dataSize;
pVorbis->push.dataSize = dataSize;
pVorbis->push.dataCapacity = dataCapacity;
pVorbis->push.dataCapacity = dataCapacity;
return MA_SUCCESS;
}
#endif
MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_stbvorbis* pVorbis)
{
ma_result result;
result = ma_stbvorbis_init_internal(pConfig, pVorbis);
if (result != MA_SUCCESS) {
return result;
}
if (onRead == NULL || onSeek == NULL) {
return MA_INVALID_ARGS; /* onRead and onSeek are mandatory. */
}
pVorbis->onRead = onRead;
pVorbis->onSeek = onSeek;
pVorbis->onTell = onTell;
pVorbis->pReadSeekTellUserData = pReadSeekTellUserData;
ma_allocation_callbacks_init_copy(&pVorbis->allocationCallbacks, pAllocationCallbacks);
#if !defined(MA_NO_VORBIS)
{
/*
stb_vorbis lacks a callback based API for it's pulling API which means we're stuck with the
pushing API. In order for us to be able to successfully initialize the decoder we need to
supply it with enough data. We need to keep loading data until we have enough.
*/
result = ma_stbvorbis_init_internal_decoder_push(pVorbis);
if (result != MA_SUCCESS) {
return result;
}
pVorbis->usingPushMode = MA_TRUE;
pVorbis->usingPushMode = MA_TRUE;
result = ma_stbvorbis_post_init(pVorbis);
result = ma_stbvorbis_post_init(pVorbis);
if (result != MA_SUCCESS) {
if (result != MA_SUCCESS) {
stb_vorbis_close(pVorbis->stb);
stb_vorbis_close(pVorbis->stb);
ma_free(pData, pAllocationCallbacks);
ma_free(p
Vorbis->push.p
Data, pAllocationCallbacks);
return result;
return result;
}
}
...
@@ -63079,28 +63090,39 @@ MA_API ma_result ma_stbvorbis_seek_to_pcm_frame(ma_stbvorbis* pVorbis, ma_uint64
...
@@ -63079,28 +63090,39 @@ MA_API ma_result ma_stbvorbis_seek_to_pcm_frame(ma_stbvorbis* pVorbis, ma_uint64
ma_result result;
ma_result result;
float buffer[4096];
float buffer[4096];
/*
/* If we're seeking backwards, we need to seek back to the start and then brute-force forward. */
This is terribly inefficient because stb_vorbis does not have a good seeking solution with it's push API. Currently this just performs
if (frameIndex < pVorbis->cursor) {
a full decode right from the start of the stream. Later on I'll need to write a layer that goes through all of the Ogg pages until we
if (frameIndex > 0x7FFFFFFF) {
find the one containing the sample we need. Then we know exactly where to seek for stb_vorbis.
return MA_INVALID_ARGS; /* Trying to seek beyond the 32-bit maximum of stb_vorbis. */
}
TODO: Use seeking logic documented for stb_vorbis_flush_pushdata().
/*
This is wildly inefficient due to me having trouble getting sample exact seeking working
robustly with stb_vorbis_flush_pushdata(). The only way I can think to make this work
perfectly is to reinitialize the decoder. Note that we only enter this path when seeking
backwards. This will hopefully be removed once we get our own Vorbis decoder implemented.
*/
*/
stb_vorbis_close(pVorbis->stb);
ma_free(pVorbis->push.pData, &pVorbis->allocationCallbacks);
/* Seek to the start of the audio data in the file to begin with. */
MA_ZERO_OBJECT(&pVorbis->push);
result = pVorbis->onSeek(pVorbis->pReadSeekTellUserData, pVorbis->push.audioStartOffsetInBytes, ma_seek_origin_start);
/* Seek to the start of the file. */
result = pVorbis->onSeek(pVorbis->pReadSeekTellUserData, 0, ma_seek_origin_start);
if (result != MA_SUCCESS) {
if (result != MA_SUCCESS) {
return result;
return result;
}
}
stb_vorbis_flush_pushdata(pVorbis->stb
);
result = ma_stbvorbis_init_internal_decoder_push(pVorbis
);
pVorbis->push.framesConsumed = 0;
if (result != MA_SUCCESS) {
pVorbis->push.framesRemaining = 0
;
return result
;
pVorbis->push.dataSize = 0;
}
/* Move the cursor back to the start. We'll increment this in the loop below
. */
/* At this point we should be sitting on the first frame
. */
pVorbis->cursor = 0;
pVorbis->cursor = 0;
}
/* We're just brute-forcing this for now. */
while (pVorbis->cursor < frameIndex) {
while (pVorbis->cursor < frameIndex) {
ma_uint64 framesRead;
ma_uint64 framesRead;
ma_uint64 framesToRead = ma_countof(buffer)/pVorbis->channels;
ma_uint64 framesToRead = ma_countof(buffer)/pVorbis->channels;
...
@@ -68467,7 +68489,7 @@ static ma_data_source_vtable g_ma_resource_manager_data_stream_vtable =
...
@@ -68467,7 +68489,7 @@ static ma_data_source_vtable g_ma_resource_manager_data_stream_vtable =
ma_resource_manager_data_stream_cb__get_cursor_in_pcm_frames,
ma_resource_manager_data_stream_cb__get_cursor_in_pcm_frames,
ma_resource_manager_data_stream_cb__get_length_in_pcm_frames,
ma_resource_manager_data_stream_cb__get_length_in_pcm_frames,
ma_resource_manager_data_stream_cb__set_looping,
ma_resource_manager_data_stream_cb__set_looping,
MA_DATA_SOURCE_SELF_MANAGED_RANGE_AND_LOOP_POINT
0 /*MA_DATA_SOURCE_SELF_MANAGED_RANGE_AND_LOOP_POINT*/
};
};
static void ma_resource_manager_data_stream_set_absolute_cursor(ma_resource_manager_data_stream* pDataStream, ma_uint64 absoluteCursor)
static void ma_resource_manager_data_stream_set_absolute_cursor(ma_resource_manager_data_stream* pDataStream, ma_uint64 absoluteCursor)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment