public Instrument()
        {
            string sampleFolder = this.GetSampleFolder();

            this.minSample = this.GetMinSample();
            this.maxSample = this.GetMaxSample();
            int digitCount = this.GetFileDigitCount();

            this.isLoop             = this.GetIsLoop();
            this.isNoteOffOnRelease = this.GetIsNoteOffOnRelease();

            Mixer.ChannelsAllocated = channelCount;

            this.samples         = new Sample[maxSample + 1];
            this.soundChannelMap = new Channel[128];

            this.channels = new Channel[channelCount];
            for (int channelId = 0; channelId < channelCount; ++channelId)
            {
                this.channels[channelId] = Mixer.CreateChannel(channelId);
            }

            for (int sampleId = minSample; sampleId < maxSample + 1; ++sampleId)
            {
                Sample sample = new Sample(sampleId, sampleFolder + "/" + this.FormatDigit(sampleId, digitCount) + ".ogg");
                this.samples[sampleId] = sample;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Setup the audio subsystem
        /// </summary>
        /// <param name="callingForm">The Calling Form</param>
        public static void setupAudio(System.Windows.Forms.Control callingForm)
        {
            // Open the mixer with, high quality
            Mixer.Open(44100, AudioFormat.Default, (int)SoundChannel.Stereo, 1024);

            // Make sure enough channels are allocated to cover the complete sample range
            Mixer.ChannelsAllocated = channels * subChannels; // Set the maximum number of channels to 1000

            //ch = new Channel[channels,subChannels];
            ch = new Channel[channels][];

            // Setup the subChannels which will be cycled through to ensure that the quality is maintained
            for (int i = 0; i < channels; i++)
            {
                ch[i] = new Channel[subChannels];
            }

            // Need a unique count for channels; otherwise if the same channel declaration is assigned to
            // more than one position; all of those positions would be effected by any directive.
            // I.e. Calling play on one array position which has the same channel as another array position
            // would then be accessing the same properties
            int channelAllocated = 0;

            // Create all of the channels; so that the audio can be assigned to and played from the channel
            for (int i = 0; i < channels; i++)
            {
                for (int p = 0; p < subChannels; p++)
                {
                    // Create the channels that the audio can be played in to
                    ch[i][p] = Mixer.CreateChannel(channelAllocated++);
                }
            }

            aSound = new Sound[255];

            //// Setup the array to store the individual samples for each level of power
            //for (int i = 0; i < 3; i++)
            //{
            //    aSound[i] = new Sound();
            //}


            // For the pitch shifting roll
            aSample = new sample[262];

            for (int i = 0; i < 261; i++)
            {
                //sampleLocations[i] = "";
                loopSample[i] = false;
            }



            //SDL Interface Initalised
            SDLInitalised = true;
        }