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)

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


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 38611 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
ASSIGNED

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!