Example #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (!isPlaying)
            {
                GmeNative.gme_start_track(emuHandle, track++);
                isPlaying = true;
            }

            // Make a buffer and fill it.
            short[] sBuffer = new short[count / 2];
            GmeNative.gme_play(emuHandle, count / 2, sBuffer);

            // Convert the short samples to byte samples and place them
            // in the NAudio byte sample buffer.
            Buffer.BlockCopy(sBuffer, 0, buffer, 0, buffer.Length);

            return(buffer.Length);
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fileName">File to open using Game Music Emu.</param>
        /// <param name="sampleRate">Desired sample rate. Defaults to 44100Hz if not specified.</param>
        /// <param name="channels">Number of channels to use. Defaults to two if not specified.</param>
        public GmeReader(string fileName, int sampleRate = 44100, int channels = 2)
        {
            // Open the file.
            this.emuHandle = GmeNative.OpenFile(fileName, sampleRate);

            // Enable accurate sound emulation.
            GmeNative.gme_enable_accuracy(emuHandle, true);

            // Get track info
            this.TrackInfo  = GmeNative.GetTrackInfo(emuHandle, track);
            this.TrackCount = GmeNative.gme_track_count(emuHandle);
            this.VoiceCount = GmeNative.gme_voice_count(emuHandle);
            this.Equalizer  = GmeNative.GetEqualizer(emuHandle);
            this.Type       = GmeNative.GetType(emuHandle);

            GmeType tempType = this.Type; // Since properties can't be used in ref arguments.

            this.SupportsMultipleTracks = GmeNative.gme_type_multitrack(ref tempType);

            // Init the wave format.
            this.waveFormat = new WaveFormat(sampleRate, 16, channels);
        }
Example #3
0
 public void Unload()
 {
     GmeNative.gme_delete(emuHandle);
 }
Example #4
0
 // TODO: documentation
 public void SetTempo(double tempo)
 {
     GmeNative.SetTempo(emuHandle, tempo);
 }
Example #5
0
 // TODO: documentation
 // i think this determines when the song starts to fade out?? not sure wtf it does yet
 public void SetFade(int msLength)
 {
     GmeNative.SetFade(emuHandle, msLength);
 }
Example #6
0
 // TODO: documentation
 // 0 to 1
 public void SetStereoDepth(double depth)
 {
     GmeNative.SetStereoDepth(emuHandle, depth);
 }
Example #7
0
 // TODO: documentation
 // see GmeEqualizer for value ranges
 public void SetEqualizer(double treble, double bass)
 {
     GmeNative.SetEqualizer(emuHandle, treble, bass);
 }
Example #8
0
 // TODO: documentation
 public void MuteVoices(int mutingMask)
 {
     GmeNative.MuteVoices(emuHandle, mutingMask);
 }
Example #9
0
 // TODO: documentation
 public void MuteVoice(int voiceIndex, int mute)
 {
     GmeNative.MuteVoice(emuHandle, voiceIndex, mute);
 }
Example #10
0
 /// <summary>
 /// Gets the name of a voice in the track.
 /// </summary>
 /// <param name="voiceIndex">Voice index of the voice to get the name of.</param>
 /// <returns>The name of the voice specified by the given index.</returns>
 public string GetVoiceName(int voiceIndex)
 {
     return(GmeNative.GetVoiceName(emuHandle, voiceIndex));
 }