Bug 38611 - AVAudioPcmBuffer: provide better API to prevent API misuse
Summary: AVAudioPcmBuffer: provide better API to prevent API misuse
Status: ASSIGNED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: master
Hardware: PC Mac OS
: Low enhancement
Target Milestone: Untriaged
Assignee: Alex Soto [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-02-10 09:29 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2016-03-09 14:47 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
TestCase.zip (10.70 KB, application/zip)
2016-02-10 09:29 UTC, Rolf Bjarne Kvinge [MSFT]
Details

Description Rolf Bjarne Kvinge [MSFT] 2016-02-10 09:29:54 UTC
Created attachment 14977 [details]
TestCase.zip

See attached sample for how a customer misused the API and didn't get what they wanted.

In short they assumed the Int16ChannelData is a pointer to audio samples, when it's a pointer to an array of pointers to audio samples.

We can provide a better API for copying audio data, that also does validation:

    CopyTo (byte[][] buffer) // write all samples
    CopyTo (byte[][] buffer, int firstSample, int sampleCount) // validate sample range
    CopyTo (short[][] buffer) // validate format is int16
    CopyTo (short[][] buffer, int firstSample, int sampleCount)
    CopyTo (int[][] buffer)
    CopyTo (int[][] buffer, int firstSample, int sampleCount)
    CopyTo (float[][] buffer)
    CopyTo (float[][] buffer, int firstSample, int sampleCount)
    // all methods validate that the number of entries in the arrays matches the number of channels, and each sub-array is big enough for the samples

this way the sample code that does:

    Marshal.Copy(buffer.Int16ChannelData, channelData, 0, (int)buffer.FrameLength);

can be replaced with:

    buffer.CopyTo (new short [][] { buffer });
Comment 1 Sebastien Pouliot 2016-03-09 14:47:10 UTC
@Alex that's similar to another (post-poned) bug. Rolf's idea sounds good, can you verify if it would cover (same pattern if not same code) the other existing case ? thanks!

Note You need to log in before you can comment on or make changes to this bug.