예제 #1
0
        protected void LoadAudioFile(StreamInfoProvider info)
        {
            // get the path to the file
            string path;

            if (info.IsInternal)
            {
                path = NSBundle.MainBundle.PathForSoundResource(info.Uri);
            }
            else
            {
                // file path is the Uri for user sources
                path = info.Uri;
            }

            using (var url = CFUrl.FromFile(path))
            {
                using (var file = ExtAudioFile.OpenUrl(url))
                {
                    var clientFormat = file.FileDataFormat;
                    clientFormat.FormatFlags       = AudioStreamBasicDescription.AudioFormatFlagsNativeFloat;
                    clientFormat.ChannelsPerFrame  = 1;
                    clientFormat.FramesPerPacket   = 1;
                    clientFormat.BitsPerChannel    = 8 * sizeof(float);
                    clientFormat.BytesPerPacket    =
                        clientFormat.BytesPerFrame = clientFormat.ChannelsPerFrame * sizeof(float);

                    file.ClientDataFormat = clientFormat;

                    double rateRatio = Metronome.SampleRate / clientFormat.SampleRate;

                    var numFrames = file.FileLengthFrames;
                    numFrames = (uint)(numFrames * rateRatio);

                    TotalFrames = numFrames;

                    UInt32 samples  = (uint)(numFrames * clientFormat.ChannelsPerFrame);
                    var    dataSize = (int)(sizeof(uint) * samples);
                    Data = Marshal.AllocHGlobal(dataSize);

                    // set up a AudioBufferList to read data into
                    var bufList = new AudioBuffers(1);
                    bufList[0] = new AudioBuffer
                    {
                        NumberChannels = 1,
                        Data           = Data,
                        DataByteSize   = dataSize
                    };

                    ExtAudioFileError error;
                    file.Read((uint)numFrames, bufList, out error);
                    if (error != ExtAudioFileError.OK)
                    {
                        throw new ApplicationException();
                    }
                }
            }
        }
예제 #2
0
        public Mixer()
        {
            BuildAUGraph();

            _converter = AudioConverter.Create(MixerNode.GetAudioFormat(AudioUnitScopeType.Output), AudioStreamBasicDescription.CreateLinearPCM());

            Metronome.Instance.TempoChanged += TempoChanged;

            _countOff = new PitchStream(StreamInfoProvider.GetDefault(), null);
            _countOff.IntervalLoop = new SampleIntervalLoop(_countOff, new double[] { 1 });
            _countOff.AddFrequency("A4");
        }
예제 #3
0
 public PitchStream(StreamInfoProvider info, Layer layer) : base(info, layer)
 {
     // Create the audio format
     _format = new AudioStreamBasicDescription()
     {
         SampleRate       = Metronome.SampleRate,
         Format           = AudioFormatType.LinearPCM,
         FormatFlags      = AudioStreamBasicDescription.AudioFormatFlagsAudioUnitNativeFloat, //AudioFormatFlags.IsFloat | AudioFormatFlags.IsPacked | AudioFormatFlags.IsNonInterleaved,
         BitsPerChannel   = 32,
         ChannelsPerFrame = 2,
         FramesPerPacket  = 1,
         BytesPerFrame    = 4,
         BytesPerPacket   = 4
     };
 }
예제 #4
0
        public WavFileStream(StreamInfoProvider info, Layer layer) : base(info, layer)
        {
            _format = new AudioStreamBasicDescription()
            {
                BitsPerChannel   = 32,
                Format           = AudioFormatType.LinearPCM,
                FormatFlags      = AudioStreamBasicDescription.AudioFormatFlagsAudioUnitNativeFloat,
                SampleRate       = Metronome.SampleRate,
                ChannelsPerFrame = 2,
                FramesPerPacket  = 1,
                BytesPerFrame    = sizeof(float),
                BytesPerPacket   = sizeof(float)
            };

            LoadAudioFile(info);
        }
예제 #5
0
        public static void ImportMetronome(Pronome.Metronome m)
        {
            // remove all current layers
            foreach (Layer layer in Metronome.Instance.Layers.ToArray())
            {
                layer.Controller.Remove();
            }

            // add new layers
            foreach (Pronome.Layer layer in m.Layers)
            {
                var controller = TransportViewController.Instance;
                controller.NewLayer(
                    layer.ParsedString,
                    StreamInfoProvider.GetFromUri(layer.BaseSourceName),
                    layer.ParsedOffset,
                    layer.pan,
                    (float)layer.volume);
            }

            // set the tempo and volume
            Metronome.Instance.Volume = (nfloat)m.Volume;
            Metronome.Instance.Tempo  = (nfloat)m.Tempo;
        }