Exemple #1
0
 public JobInfo(SynthMode synthMode, string text, SynthOption synthOption, uint kanaBufBytes, uint waveBufBytes)
 {
     this.JobID      = 0;
     this.BeginPause = 0;
     this.TermPause  = 0;
     this.KanaBuffer = new StringBuilder((int)kanaBufBytes);
     this.WaveBuffer = new short[waveBufBytes / 2];
     this.Text       = text;
     if ((synthOption & SynthOption.IgnoreNewLine) == SynthOption.IgnoreNewLine)
     {
         this.IgnoreNewLine = true;
         this.SynthText     = this.Text.Replace("\n", null);
         this.MakePosConvertTable();
     }
     else
     {
         this.IgnoreNewLine = false;
         this.SynthText     = this.Text;
         this.MakePosConvertTable();
     }
     this.CurrentTextPos         = 0;
     this.LastBookmarkPos        = 0;
     this.TextProcessingDone     = (synthMode & SynthMode.TextProcess) != SynthMode.TextProcess;
     this.SynthesizingDone       = (synthMode & SynthMode.Synthesize) != SynthMode.Synthesize;
     this.Aborted                = false;
     this.TextProcessingProgress = 0;
     this.SynthesizingProgress   = 0;
     this.CurrentIndex           = 0;
     this.NextSentenceStartTick  = 0L;
     this.TextBlockList          = new List <TextBlock>();
     this.AudioEventQueue        = new Queue <AITalkUtilEx.AudioEventParam>();
 }
Exemple #2
0
            /// <summary>
            /// Generate blocks of data in specific modes.
            /// </summary>
            /// <returns>The template.</returns>
            /// <param name="mode">Mode.</param>
            /// <param name="chip">Chip.</param>
            /// <param name="samples">Samples.</param>
            /// <param name="output">Output.</param>
            /// <param name="pos">Position.</param>
            Channel BlockTemplate(SynthMode mode, Chip chip, int samples, short[] output, int pos)
            {
                switch (mode)
                {
                case SynthMode.Sm2AM:
                case SynthMode.Sm3AM:
                    if (Op(0).Silent() && Op(1).Silent())
                    {
                        old[0] = old[1] = 0;
                        return(Chip.Channels[ChannelNum + 1]);
                    }
                    break;

                case SynthMode.Sm2FM:
                case SynthMode.Sm3FM:
                    if (Op(1).Silent())
                    {
                        old[0] = old[1] = 0;
                        return(Chip.Channels[ChannelNum + 1]);
                    }
                    break;

                case SynthMode.Sm3FMFM:
                    if (Op(3).Silent())
                    {
                        old[0] = old[1] = 0;
                        return(Chip.Channels[ChannelNum + 2]);
                    }
                    break;

                case SynthMode.Sm3AMFM:
                    if (Op(0).Silent() && Op(3).Silent())
                    {
                        old[0] = old[1] = 0;
                        return(Chip.Channels[ChannelNum + 2]);
                    }
                    break;

                case SynthMode.Sm3FMAM:
                    if (Op(1).Silent() && Op(3).Silent())
                    {
                        old[0] = old[1] = 0;
                        return(Chip.Channels[ChannelNum + 2]);
                    }
                    break;

                case SynthMode.Sm3AMAM:
                    if (Op(0).Silent() && Op(2).Silent() && Op(3).Silent())
                    {
                        old[0] = old[1] = 0;
                        return(Chip.Channels[ChannelNum + 2]);
                    }
                    break;

                case SynthMode.Sm2Percussion:
                    // This case was not handled in the DOSBox code either
                    // thus we leave this blank.
                    // TODO: Consider checking this.
                    break;

                case SynthMode.Sm3Percussion:
                    // This case was not handled in the DOSBox code either
                    // thus we leave this blank.
                    // TODO: Consider checking this.
                    break;

                case SynthMode.Sm4Start:
                    // This case was not handled in the DOSBox code either
                    // thus we leave this blank.
                    // TODO: Consider checking this.
                    break;

                case SynthMode.Sm6Start:
                    // This case was not handled in the DOSBox code either
                    // thus we leave this blank.
                    // TODO: Consider checking this.
                    break;
                }
                //Init the operators with the the current vibrato and tremolo values
                Op(0).Prepare(chip);
                Op(1).Prepare(chip);
                if (mode > SynthMode.Sm4Start)
                {
                    Op(2).Prepare(chip);
                    Op(3).Prepare(chip);
                }
                if (mode > SynthMode.Sm6Start)
                {
                    Op(4).Prepare(chip);
                    Op(5).Prepare(chip);
                }
                for (int i = 0; i < samples; i++)
                {
                    //Early out for percussion handlers
                    if (mode == SynthMode.Sm2Percussion)
                    {
                        GeneratePercussion(false, chip, output, pos + i);
                        continue;   //Prevent some unitialized value bitching
                    }
                    if (mode == SynthMode.Sm3Percussion)
                    {
                        GeneratePercussion(true, chip, output, pos + i * 2);
                        continue;   //Prevent some unitialized value bitching
                    }

                    //Do unsigned shift so we can shift out all bits but still stay in 10 bit range otherwise
                    int mod = (old[0] + old[1]) >> feedback;
                    old[0] = old[1];
                    old[1] = Op(0).GetSample(mod);
                    short sample = 0;
                    short out0   = old[0];
                    if (mode == SynthMode.Sm2AM || mode == SynthMode.Sm3AM)
                    {
                        sample = (short)(out0 + Op(1).GetSample(0));
                    }
                    else if (mode == SynthMode.Sm2FM || mode == SynthMode.Sm3FM)
                    {
                        sample = Op(1).GetSample(out0);
                    }
                    else if (mode == SynthMode.Sm3FMFM)
                    {
                        int next = Op(1).GetSample(out0);
                        next   = Op(2).GetSample(next);
                        sample = Op(3).GetSample(next);
                    }
                    else if (mode == SynthMode.Sm3AMFM)
                    {
                        sample = out0;
                        int next = Op(1).GetSample(0);
                        next    = Op(2).GetSample(next);
                        sample += Op(3).GetSample(next);
                    }
                    else if (mode == SynthMode.Sm3FMAM)
                    {
                        sample = Op(1).GetSample(out0);
                        int next = Op(2).GetSample(0);
                        sample += Op(3).GetSample(next);
                    }
                    else if (mode == SynthMode.Sm3AMAM)
                    {
                        sample = out0;
                        int next = Op(1).GetSample(0);
                        sample += Op(2).GetSample(next);
                        sample += Op(3).GetSample(0);
                    }
                    switch (mode)
                    {
                    case SynthMode.Sm2AM:
                    case SynthMode.Sm2FM:
                        output[pos + i] += sample;
                        break;

                    case SynthMode.Sm3AM:
                    case SynthMode.Sm3FM:
                    case SynthMode.Sm3FMFM:
                    case SynthMode.Sm3AMFM:
                    case SynthMode.Sm3FMAM:
                    case SynthMode.Sm3AMAM:
                        output[pos + i * 2 + 0] += (short)(sample & maskLeft);
                        output[pos + i * 2 + 1] += (short)(sample & maskRight);
                        break;

                    case SynthMode.Sm2Percussion:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;

                    case SynthMode.Sm3Percussion:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;

                    case SynthMode.Sm4Start:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;

                    case SynthMode.Sm6Start:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;
                    }
                }
                switch (mode)
                {
                case SynthMode.Sm2AM:
                case SynthMode.Sm2FM:
                case SynthMode.Sm3AM:
                case SynthMode.Sm3FM:
                    return(Chip.Channels[ChannelNum + 1]);

                case SynthMode.Sm3FMFM:
                case SynthMode.Sm3AMFM:
                case SynthMode.Sm3FMAM:
                case SynthMode.Sm3AMAM:
                    return(Chip.Channels[ChannelNum + 2]);

                case SynthMode.Sm2Percussion:
                case SynthMode.Sm3Percussion:
                    return(Chip.Channels[ChannelNum + 3]);

                case SynthMode.Sm4Start:
                    // This case was not handled in the DOSBox code either
                    // thus we leave this blank.
                    // TODO: Consider checking this.
                    break;

                case SynthMode.Sm6Start:
                    // This case was not handled in the DOSBox code either
                    // thus we leave this blank.
                    // TODO: Consider checking this.
                    break;
                }
                return(null);
            }
Exemple #3
0
            /// <summary>
            /// Generate blocks of data in specific modes.
            /// </summary>
            /// <returns>The template.</returns>
            /// <param name="mode">Mode.</param>
            /// <param name="chip">Chip.</param>
            /// <param name="samples">Samples.</param>
            /// <param name="output">Output.</param>
            /// <param name="pos">Position.</param>
            Channel BlockTemplate(SynthMode mode, Chip chip, uint samples, int[] output, int pos)
            {
                switch (mode)
                {
                    case SynthMode.Sm2AM:
                    case SynthMode.Sm3AM:
                        if (Op(0).Silent() && Op(1).Silent())
                        {
                            old[0] = old[1] = 0;
                            return Chip.Channels[ChannelNum + 1];
                        }
                        break;
                    case SynthMode.Sm2FM:
                    case SynthMode.Sm3FM:
                        if (Op(1).Silent())
                        {
                            old[0] = old[1] = 0;
                            return Chip.Channels[ChannelNum + 1];
                        }
                        break;
                    case SynthMode.Sm3FMFM:
                        if (Op(3).Silent())
                        {
                            old[0] = old[1] = 0;
                            return Chip.Channels[ChannelNum + 2];
                        }
                        break;
                    case SynthMode.Sm3AMFM:
                        if (Op(0).Silent() && Op(3).Silent())
                        {
                            old[0] = old[1] = 0;
                            return Chip.Channels[ChannelNum + 2];
                        }
                        break;
                    case SynthMode.Sm3FMAM:
                        if (Op(1).Silent() && Op(3).Silent())
                        {
                            old[0] = old[1] = 0;
                            return Chip.Channels[ChannelNum + 2];
                        }
                        break;
                    case SynthMode.Sm3AMAM:
                        if (Op(0).Silent() && Op(2).Silent() && Op(3).Silent())
                        {
                            old[0] = old[1] = 0;
                            return Chip.Channels[ChannelNum + 2];
                        }
                        break;
                    case SynthMode.Sm2Percussion:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;
                    case SynthMode.Sm3Percussion:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;
                    case SynthMode.Sm4Start:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;
                    case SynthMode.Sm6Start:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;
                }
                //Init the operators with the the current vibrato and tremolo values
                Op(0).Prepare(chip);
                Op(1).Prepare(chip);
                if (mode > SynthMode.Sm4Start)
                {
                    Op(2).Prepare(chip);
                    Op(3).Prepare(chip);
                }
                if (mode > SynthMode.Sm6Start)
                {
                    Op(4).Prepare(chip);
                    Op(5).Prepare(chip);
                }
                for (int i = 0; i < samples; i++)
                {
                    //Early out for percussion handlers
                    if (mode == SynthMode.Sm2Percussion)
                    {
                        GeneratePercussion(false, chip, output, pos + i);
                        continue;   //Prevent some unitialized value bitching
                    }
                    else if (mode == SynthMode.Sm3Percussion)
                    {
                        GeneratePercussion(true, chip, output, pos + i * 2);
                        continue;   //Prevent some unitialized value bitching
                    }

                    //Do unsigned shift so we can shift out all bits but still stay in 10 bit range otherwise
                    int mod = (int)((old[0] + old[1]) >> feedback);
                    old[0] = old[1];
                    old[1] = Op(0).GetSample(mod);
                    int sample = 0;
                    int out0 = old[0];
                    if (mode == SynthMode.Sm2AM || mode == SynthMode.Sm3AM)
                    {
                        sample = out0 + Op(1).GetSample(0);
                    }
                    else if (mode == SynthMode.Sm2FM || mode == SynthMode.Sm3FM)
                    {
                        sample = Op(1).GetSample(out0);
                    }
                    else if (mode == SynthMode.Sm3FMFM)
                    {
                        int next = Op(1).GetSample(out0);
                        next = Op(2).GetSample(next);
                        sample = Op(3).GetSample(next);
                    }
                    else if (mode == SynthMode.Sm3AMFM)
                    {
                        sample = out0;
                        int next = Op(1).GetSample(0);
                        next = Op(2).GetSample(next);
                        sample += Op(3).GetSample(next);
                    }
                    else if (mode == SynthMode.Sm3FMAM)
                    {
                        sample = Op(1).GetSample(out0);
                        int next = Op(2).GetSample(0);
                        sample += Op(3).GetSample(next);
                    }
                    else if (mode == SynthMode.Sm3AMAM)
                    {
                        sample = out0;
                        int next = Op(1).GetSample(0);
                        sample += Op(2).GetSample(next);
                        sample += Op(3).GetSample(0);
                    }
                    switch (mode)
                    {
                        case SynthMode.Sm2AM:
                        case SynthMode.Sm2FM:
                            output[pos + i] += sample;
                            break;
                        case SynthMode.Sm3AM:
                        case SynthMode.Sm3FM:
                        case SynthMode.Sm3FMFM:
                        case SynthMode.Sm3AMFM:
                        case SynthMode.Sm3FMAM:
                        case SynthMode.Sm3AMAM:
                            output[pos + i * 2 + 0] += sample & maskLeft;
                            output[pos + i * 2 + 1] += sample & maskRight;
                            break;
                        case SynthMode.Sm2Percussion:
                                // This case was not handled in the DOSBox code either
                                // thus we leave this blank.
                                // TODO: Consider checking this.
                            break;
                        case SynthMode.Sm3Percussion:
                                // This case was not handled in the DOSBox code either
                                // thus we leave this blank.
                                // TODO: Consider checking this.
                            break;
                        case SynthMode.Sm4Start:
                                // This case was not handled in the DOSBox code either
                                // thus we leave this blank.
                                // TODO: Consider checking this.
                            break;
                        case SynthMode.Sm6Start:
                                // This case was not handled in the DOSBox code either
                                // thus we leave this blank.
                                // TODO: Consider checking this.
                            break;
                    }
                }
                switch (mode)
                {
                    case SynthMode.Sm2AM:
                    case SynthMode.Sm2FM:
                    case SynthMode.Sm3AM:
                    case SynthMode.Sm3FM:
                        return Chip.Channels[ChannelNum + 1];
                    case SynthMode.Sm3FMFM:
                    case SynthMode.Sm3AMFM:
                    case SynthMode.Sm3FMAM:
                    case SynthMode.Sm3AMAM:
                        return Chip.Channels[ChannelNum + 2];
                    case SynthMode.Sm2Percussion:
                    case SynthMode.Sm3Percussion:
                        return Chip.Channels[ChannelNum + 3];
                    case SynthMode.Sm4Start:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;
                    case SynthMode.Sm6Start:
                        // This case was not handled in the DOSBox code either
                        // thus we leave this blank.
                        // TODO: Consider checking this.
                        break;
                }
                return null;
            }