Exemple #1
0
        public static string loadSample(string fileLocation, int position)
        {
            Microsoft.DirectX.DirectSound.BufferDescription bufferDes = new BufferDescription();
            bufferDes.CanGetCurrentPosition = true;
            bufferDes.ControlFrequency      = true;
            bufferDes.ControlPan            = true;
            bufferDes.ControlVolume         = true;
            bufferDes.GlobalFocus           = true;
            bufferDes.ControlEffects        = true;

            try
            {
                aSound[position] = new SecondaryBuffer(fileLocation, bufferDes, aSoundCard);
                freq[position]   = aSound[position].Frequency;

                //For Frequency Roll
                aSample[position] = new sample();

                loadedSamples++;
                return("");
            }
            catch (Exception e)
            {
                return(e.Message.ToString());
            }
        }
Exemple #2
0
        public static string setupBlankSample(int position, int size, int sampleToCopy)
        {
            // Used when speeding up samples so that the new buffer
            // matches the size of the actual sample, rather than leaving
            // an amount of space at the end, which sounds like shit
            // when it's played as a loop.

            // This lovely and seemingly useless block of code was a pain
            // to pinpoint. When I was trying to create a blank buffer
            // using a memory stream, I recived a System.ArgumentException
            // the painful peice being that I could't pin point which argument
            // was invalid. For those of you at home, you need to setup the
            // waveFormatTag FIRST, then create the buffer. This peice I
            // missed when reading the instructions as it is done automatically
            // when loading from a file but if your copying a memory stream
            // it obviously doesn't know what exactly is in the stream, so
            // you need to define it - even if you are copying an existing stream..

            // If any one from Micr0$0ft reads this - I would really think a few
            // more examples would be handy when your dealing with parts of the
            // api which aren't going to return freindly error messages..

            Microsoft.DirectX.DirectSound.WaveFormat waveFormatTag = new WaveFormat();
            waveFormatTag.AverageBytesPerSecond = aSound[sampleToCopy].Format.AverageBytesPerSecond;
            waveFormatTag.BitsPerSample         = aSound[sampleToCopy].Format.BitsPerSample;
            waveFormatTag.BlockAlign            = aSound[sampleToCopy].Format.BlockAlign;
            waveFormatTag.Channels         = aSound[sampleToCopy].Format.Channels;
            waveFormatTag.FormatTag        = aSound[sampleToCopy].Format.FormatTag;
            waveFormatTag.SamplesPerSecond = aSound[sampleToCopy].Format.SamplesPerSecond;

            // After the wave format header is defined, setting up the empty
            // buffer follows the same principles as loading from a file.

            Microsoft.DirectX.DirectSound.BufferDescription bufferDes = new BufferDescription(waveFormatTag);
            bufferDes.CanGetCurrentPosition = true;
            bufferDes.ControlFrequency      = true;
            bufferDes.ControlPan            = true;
            bufferDes.ControlVolume         = true;
            bufferDes.GlobalFocus           = true;
            bufferDes.ControlEffects        = true;
            bufferDes.BufferBytes           = size;

            try
            {
                aSound[position] = new SecondaryBuffer(bufferDes, aSoundCard);

                // Required for frequency roll mod - and yes it s not used for the scratch interface
                freq[position]    = aSound[position].Frequency;
                aSample[position] = new sample();

                return("");
            }
            catch (Exception e)
            {
                return(e.Message.ToString());
            }
        }