0

Is there a property on the AVAudioPlayer class that I can use to get the samples? If not is there another class I can use to get this information?

Here's what I have:

var openDialog = NSOpenPanel.OpenPanel;
openDialog.CanChooseFiles = true;
openDialog.CanChooseDirectories = false;
openDialog.AllowedFileTypes = new string[] { "wav" };

if (openDialog.RunModal() == 1)
{

    var url = openDialog.Urls[0];

    if (url != null)
    {
        var path = url.Path;
        var audioplayer = AVFoundation.AVAudioPlayer.FromUrl(file);
        var samples = audioplayer.SAMPLES?;

Visual Studio Mac (C# / Xamarin)

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231

1 Answers1

1

AVAudioPlayer does not give you access to the sample data, but if you switch playback to AVPlayer you can use an MTAudioProcessingTap to "tap" the samples as they are played.

If you simply want to examine the samples in your file you can use AVAudioFile.

// get the total number of samples
var audioFile = new AVAudioFile(file, out outError);
var samples = audioFile.Length;
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • Great! i’ll check when i get home. Will that help me get the total number of samples? – 1.21 gigawatts May 17 '21 at 00:22
  • Examining the file (with `AVAudioFile` for example) will tell you that, with the tap you can sum the number of samples you see, but I'm not sure if it will tell you when the samples finish. – Rhythmic Fistman May 17 '21 at 04:53
  • I added an example of what I think is the sample length. I haven't been able to verify it though. – 1.21 gigawatts May 17 '21 at 11:38