Minor fixes to miniaudio for kew compatibility#1095
Conversation
|
Thanks.
I won't be merging this PR as is, but I'll address 1 and 3 manually. Will leave this open as a reminder. |
|
Regarding 4 I must have gotten a zero there at some point, or I wouldn't have discovered it, but it could of course have been found while some changes to kew were a work in progress due to a bug in kew. Next time I'll try to upstream these/let you know as soon as I find them, while everything is fresh in memory. |
|
1 and 3 have been addressed manually in the dev branch. For the MP3 thing, if that's ever replicated feel free to submit a separate ticket. |
While working on kew I ran into a few problems that I fixed in miniaudio.h. I'm making this PR to provide you with these fixes. You don't need to include them of course, but it would make life easier for us, because our package managers would be able to use miniaudio as an external dependency instead of vendoring without issue.
The fixes included are:
call to MultiByteToWideChar:
sizeof(filenameW) returns the total size of the buffer in bytes (4096 bytes)
but MultiByteToWideChar is expecting wide characters (wchar_t), not bytes.
Solution: divide by sizeof(WCHAR)
Added read error check in static ma_result ma_device_stop__alsa(ma_device* pDevice)
The original code checks if the number of bytes read (resultRead) is not equal to the expected number of bytes (sizeof(t))
However, it doesn't handle the possibility of an actual read() error. read() can return -1. This check has been added with a call to perror. This might not be exactly how you'd like to handle it, but I have included it in any case.
Added default value
ma_uint64 framesProcessed;
changed to:
ma_uint64 framesProcessed = 0;
in MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
Fix potential division by 0 error
int frame_bytes = ma_dr_mp3_hdr_frame_samples(h)*ma_dr_mp3_hdr_bitrate_kbps(h)*125/ma_dr_mp3_hdr_sample_rate_hz(h);
changed to:
unsigned int sampleRate = ma_dr_mp3_hdr_sample_rate_hz(h);
if (sampleRate == 0) return 0;
int frame_bytes = ma_dr_mp3_hdr_frame_samples(h)*ma_dr_mp3_hdr_bitrate_kbps(h)*125/sampleRate;
Return if userdata is null
if (pMP3->pUserData == NULL)
return 0;
added to static size_t ma_dr_mp3__on_read(ma_dr_mp3* pMP3, void* pBufferOut, size_t bytesToRead)
That's it!