mirror of
				https://github.com/haya3218/SDfmL.git
				synced 2024-08-14 23:57:09 +00:00 
			
		
		
		
	Make a speech synth to swear at you, bitch
This commit is contained in:
		
							parent
							
								
									b30611da35
								
							
						
					
					
						commit
						b9702710b7
					
				
					 7 changed files with 266 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -22,6 +22,7 @@ class MainState : public State {
 | 
			
		|||
    // to override a function, just state back the name of it with a virtual keyword
 | 
			
		||||
    // before it
 | 
			
		||||
    virtual void Create() {
 | 
			
		||||
        SPEAK("Welcome, to es dee eff emm L. A stupid fucking wrapper for ess dee L 2. Get over it, bitch", 3000.0f, 6.5f);
 | 
			
		||||
        playModPlug("data/canyon.mid");
 | 
			
		||||
        // i know that this isnt the best idea to do this
 | 
			
		||||
        // yeah, im just lazy
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,8 @@ string Render::currentMusic = "";
 | 
			
		|||
HWND Render::hwnd;
 | 
			
		||||
HWND Render::consoleD;
 | 
			
		||||
int Render::seIndex;
 | 
			
		||||
SoLoud::Speech Render::SPEAK_BITCH;
 | 
			
		||||
SoLoud::FFTFilter Render::bass;
 | 
			
		||||
 | 
			
		||||
Render::Object::Object() {
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -261,6 +263,10 @@ bool Render::Init(string window_name) {
 | 
			
		|||
 | 
			
		||||
    log("", "Finalized initialization. Command over.", NORMAL, __FILENAME__, __LINE__);
 | 
			
		||||
 | 
			
		||||
    AddExitButton();
 | 
			
		||||
 | 
			
		||||
    SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -286,6 +292,16 @@ bool Render::Update() {
 | 
			
		|||
                run = false;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            else if (event.type == SDL_SYSWMEVENT) {
 | 
			
		||||
                if (event.syswm.msg->msg.win.msg == WM_COMMAND)
 | 
			
		||||
                {
 | 
			
		||||
                    if (LOWORD(event.syswm.msg->msg.win.wParam) == 1)
 | 
			
		||||
                    {
 | 
			
		||||
                        run = false;
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        SetWindowTextA(consoleD, "Logging window");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,11 @@
 | 
			
		|||
#include "SoLoud/soloud_wavstream.h"
 | 
			
		||||
#include "SoLoud/soloud_openmpt.h"
 | 
			
		||||
#include "SoLoud/MIDI/soloud_midi.h"
 | 
			
		||||
#include "SoLoud/soloud_speech.h"
 | 
			
		||||
#include "SoLoud/soloud_vizsn.h"
 | 
			
		||||
#include "SoLoud/soloud_waveshaperfilter.h"
 | 
			
		||||
#include "SoLoud/soloud_biquadresonantfilter.h"
 | 
			
		||||
#include "SoLoud/soloud_fftfilter.h"
 | 
			
		||||
 | 
			
		||||
#include "toml.hpp"
 | 
			
		||||
#include <fstream>
 | 
			
		||||
| 
						 | 
				
			
			@ -353,5 +358,28 @@ namespace Render {
 | 
			
		|||
        config << export_ << endl;
 | 
			
		||||
        config.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // SPEAK you fucking BITCH
 | 
			
		||||
    extern SoLoud::Speech SPEAK_BITCH;
 | 
			
		||||
 | 
			
		||||
    extern SoLoud::FFTFilter bass;
 | 
			
		||||
 | 
			
		||||
    static HMENU exitButton;
 | 
			
		||||
 | 
			
		||||
    // makes A BITCH SPEAK out shit
 | 
			
		||||
    inline void SPEAK(string words, unsigned int aBaseFrequency = 3000.0f, float aBaseSpeed = 10.0f, float aBaseDeclination = 0.5f, int aBaseWaveform = KW_SQUARE) {
 | 
			
		||||
        SPEAK_BITCH.setFilter(1, &bass);
 | 
			
		||||
        SPEAK_BITCH.setParams(aBaseFrequency, aBaseSpeed, aBaseDeclination, aBaseWaveform);
 | 
			
		||||
        SPEAK_BITCH.setVolume(5.0);
 | 
			
		||||
        SPEAK_BITCH.setText(words.c_str());
 | 
			
		||||
        seIndex = se.play(SPEAK_BITCH);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline void AddExitButton() {
 | 
			
		||||
        exitButton = CreateMenu();
 | 
			
		||||
 | 
			
		||||
        AppendMenu(exitButton, MF_STRING, 1, "Exit");
 | 
			
		||||
        SetMenu(hwnd, exitButton);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										22
									
								
								src/SoLoud/darray.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/SoLoud/darray.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
#if !defined(DARRAY_H)
 | 
			
		||||
#define DARRAY_H
 | 
			
		||||
 | 
			
		||||
class darray
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
	char *mData;
 | 
			
		||||
	int mUsed;
 | 
			
		||||
	int mAllocated;
 | 
			
		||||
	int mAllocChunk;
 | 
			
		||||
public:
 | 
			
		||||
	darray();
 | 
			
		||||
	~darray();
 | 
			
		||||
	void clear();
 | 
			
		||||
	char *getDataInPos(int aPosition);
 | 
			
		||||
	void put(int aData);
 | 
			
		||||
	int getSize() const { return mUsed; }
 | 
			
		||||
	char *getData() { return mData; } 
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										153
									
								
								src/SoLoud/klatt.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								src/SoLoud/klatt.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,153 @@
 | 
			
		|||
#ifndef KLATT_H
 | 
			
		||||
#define KLATT_H
 | 
			
		||||
 | 
			
		||||
#include "resonator.h"
 | 
			
		||||
 | 
			
		||||
#define CASCADE_PARALLEL      1
 | 
			
		||||
#define ALL_PARALLEL          2
 | 
			
		||||
#define NPAR                 40
 | 
			
		||||
 | 
			
		||||
class klatt_frame
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	int mF0FundamentalFreq;          // Voicing fund freq in Hz                       
 | 
			
		||||
	int mVoicingAmpdb;               // Amp of voicing in dB,            0 to   70    
 | 
			
		||||
	int mFormant1Freq;               // First formant freq in Hz,        200 to 1300  
 | 
			
		||||
	int mFormant1Bandwidth;          // First formant bw in Hz,          40 to 1000   
 | 
			
		||||
	int mFormant2Freq;               // Second formant freq in Hz,       550 to 3000  
 | 
			
		||||
	int mFormant2Bandwidth;          // Second formant bw in Hz,         40 to 1000   
 | 
			
		||||
	int mFormant3Freq;               // Third formant freq in Hz,        1200 to 4999 
 | 
			
		||||
	int mFormant3Bandwidth;          // Third formant bw in Hz,          40 to 1000   
 | 
			
		||||
	int mFormant4Freq;               // Fourth formant freq in Hz,       1200 to 4999 
 | 
			
		||||
	int mFormant4Bandwidth;          // Fourth formant bw in Hz,         40 to 1000   
 | 
			
		||||
	int mFormant5Freq;               // Fifth formant freq in Hz,        1200 to 4999 
 | 
			
		||||
	int mFormant5Bandwidth;          // Fifth formant bw in Hz,          40 to 1000   
 | 
			
		||||
	int mFormant6Freq;               // Sixth formant freq in Hz,        1200 to 4999 
 | 
			
		||||
	int mFormant6Bandwidth;          // Sixth formant bw in Hz,          40 to 2000   
 | 
			
		||||
	int mNasalZeroFreq;              // Nasal zero freq in Hz,           248 to  528  
 | 
			
		||||
	int mNasalZeroBandwidth;         // Nasal zero bw in Hz,             40 to 1000   
 | 
			
		||||
	int mNasalPoleFreq;              // Nasal pole freq in Hz,           248 to  528  
 | 
			
		||||
	int mNasalPoleBandwidth;         // Nasal pole bw in Hz,             40 to 1000   
 | 
			
		||||
	int mAspirationAmpdb;            // Amp of aspiration in dB,         0 to   70    
 | 
			
		||||
	int mNoSamplesInOpenPeriod;      // # of samples in open period,     10 to   65   
 | 
			
		||||
	int mVoicingBreathiness;         // Breathiness in voicing,          0 to   80    
 | 
			
		||||
	int mVoicingSpectralTiltdb;      // Voicing spectral tilt in dB,     0 to   24    
 | 
			
		||||
	int mFricationAmpdb;             // Amp of frication in dB,          0 to   80    
 | 
			
		||||
	int mSkewnessOfAlternatePeriods; // Skewness of alternate periods,   0 to   40 in sample#/2
 | 
			
		||||
	int mFormant1Ampdb;              // Amp of par 1st formant in dB,    0 to   80  
 | 
			
		||||
	int mFormant1ParallelBandwidth;  // Par. 1st formant bw in Hz,       40 to 1000 
 | 
			
		||||
	int mFormant2Ampdb;              // Amp of F2 frication in dB,       0 to   80  
 | 
			
		||||
	int mFormant2ParallelBandwidth;  // Par. 2nd formant bw in Hz,       40 to 1000 
 | 
			
		||||
	int mFormant3Ampdb;              // Amp of F3 frication in dB,       0 to   80  
 | 
			
		||||
	int mFormant3ParallelBandwidth;  // Par. 3rd formant bw in Hz,       40 to 1000 
 | 
			
		||||
	int mFormant4Ampdb;              // Amp of F4 frication in dB,       0 to   80  
 | 
			
		||||
	int mFormant4ParallelBandwidth;  // Par. 4th formant bw in Hz,       40 to 1000 
 | 
			
		||||
	int mFormant5Ampdb;              // Amp of F5 frication in dB,       0 to   80  
 | 
			
		||||
	int mFormant5ParallelBandwidth;  // Par. 5th formant bw in Hz,       40 to 1000 
 | 
			
		||||
	int mFormant6Ampdb;              // Amp of F6 (same as r6pa),        0 to   80  
 | 
			
		||||
	int mFormant6ParallelBandwidth;  // Par. 6th formant bw in Hz,       40 to 2000 
 | 
			
		||||
	int mParallelNasalPoleAmpdb;     // Amp of par nasal pole in dB,     0 to   80  
 | 
			
		||||
	int mBypassFricationAmpdb;       // Amp of bypass fric. in dB,       0 to   80  
 | 
			
		||||
	int mPalallelVoicingAmpdb;       // Amp of voicing,  par in dB,      0 to   70  
 | 
			
		||||
	int mOverallGaindb;              // Overall gain, 60 dB is unity,    0 to   60  
 | 
			
		||||
	klatt_frame();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class darray;
 | 
			
		||||
class Element;
 | 
			
		||||
 | 
			
		||||
class Slope
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	float mValue;                   /* boundary value */
 | 
			
		||||
	int mTime;                      /* transition time */
 | 
			
		||||
	Slope() 
 | 
			
		||||
	{
 | 
			
		||||
		mValue = 0;
 | 
			
		||||
		mTime = 0;
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
enum KLATT_WAVEFORM
 | 
			
		||||
{
 | 
			
		||||
	KW_SAW,
 | 
			
		||||
	KW_TRIANGLE,
 | 
			
		||||
	KW_SIN,
 | 
			
		||||
	KW_SQUARE,
 | 
			
		||||
	KW_PULSE,
 | 
			
		||||
	KW_NOISE,
 | 
			
		||||
	KW_WARBLE
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class klatt
 | 
			
		||||
{
 | 
			
		||||
	// resonators
 | 
			
		||||
	resonator mParallelFormant1, mParallelFormant2, mParallelFormant3, 
 | 
			
		||||
		      mParallelFormant4, mParallelFormant5, mParallelFormant6,
 | 
			
		||||
		      mParallelResoNasalPole, mNasalPole, mNasalZero, 
 | 
			
		||||
			  mCritDampedGlotLowPassFilter, mDownSampLowPassFilter, mOutputLowPassFilter;
 | 
			
		||||
public:
 | 
			
		||||
	int mBaseF0;
 | 
			
		||||
	float mBaseSpeed;
 | 
			
		||||
	float mBaseDeclination;
 | 
			
		||||
	int mBaseWaveform;
 | 
			
		||||
 | 
			
		||||
	int mF0Flutter;
 | 
			
		||||
	int mSampleRate;
 | 
			
		||||
	int mNspFr;
 | 
			
		||||
	int mF0FundamentalFreq;        // Voicing fund freq in Hz  
 | 
			
		||||
	int mVoicingAmpdb;          // Amp of voicing in dB,    0 to   70  
 | 
			
		||||
	int mSkewnessOfAlternatePeriods;         // Skewness of alternate periods,0 to   40  
 | 
			
		||||
	int mTimeCount;     // used for f0 flutter
 | 
			
		||||
	int mNPer;          // Current loc in voicing period   40000 samp/s
 | 
			
		||||
	int mT0;            // Fundamental period in output samples times 4 
 | 
			
		||||
	int mNOpen;         // Number of samples in open phase of period  
 | 
			
		||||
	int mNMod;          // Position in period to begin noise amp. modul 
 | 
			
		||||
 | 
			
		||||
	// Various amplitude variables used in main loop
 | 
			
		||||
 | 
			
		||||
	float mAmpVoice;     // mVoicingAmpdb converted to linear gain  
 | 
			
		||||
	float mAmpBypas;     // mBypassFricationAmpdb converted to linear gain  
 | 
			
		||||
	float mAmpAspir;     // AP converted to linear gain  
 | 
			
		||||
	float mAmpFrica;     // mFricationAmpdb converted to linear gain  
 | 
			
		||||
	float mAmpBreth;     // ATURB converted to linear gain  
 | 
			
		||||
 | 
			
		||||
	// State variables of sound sources
 | 
			
		||||
 | 
			
		||||
	int mSkew;                  // Alternating jitter, in half-period units  
 | 
			
		||||
	float mVLast;               // Previous output of voice  
 | 
			
		||||
	float mNLast;               // Previous output of random number generator  
 | 
			
		||||
	float mGlotLast;            // Previous value of glotout  
 | 
			
		||||
	float mDecay;               // mVoicingSpectralTiltdb converted to exponential time const  
 | 
			
		||||
	float mOneMd;               // in voicing one-pole ELM_FEATURE_LOW-pass filter  
 | 
			
		||||
 | 
			
		||||
	unsigned int mSeed;			// random seed
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	float natural_source(int aNper);
 | 
			
		||||
 | 
			
		||||
	void frame_init();
 | 
			
		||||
	void flutter();
 | 
			
		||||
	void pitch_synch_par_reset(int ns);
 | 
			
		||||
	void parwave(short int *jwave);
 | 
			
		||||
	void init(int aBaseFrequency = 1330, float aBaseSpeed = 10.0f, float aBaseDeclination = 0.5f, int aBaseWaveform = KW_SAW);
 | 
			
		||||
	static int phone_to_elm(char *aPhoneme, int aCount, darray *aElement);
 | 
			
		||||
 | 
			
		||||
	int mElementCount;
 | 
			
		||||
	unsigned char *mElement;
 | 
			
		||||
	int mElementIndex;
 | 
			
		||||
	klatt_frame mFrame;
 | 
			
		||||
	Element * mLastElement;
 | 
			
		||||
	int mTStress;
 | 
			
		||||
	int mNTStress;
 | 
			
		||||
	Slope mStressS;
 | 
			
		||||
	Slope mStressE;
 | 
			
		||||
	float mTop;
 | 
			
		||||
	void initsynth(int aElementCount,unsigned char *aElement);
 | 
			
		||||
	int synth(int aSampleCount, short *aSamplePointer);
 | 
			
		||||
	klatt();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										44
									
								
								src/SoLoud/resonator.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/SoLoud/resonator.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
#ifndef RESONATOR_H
 | 
			
		||||
#define RESONATOR_H
 | 
			
		||||
 | 
			
		||||
class resonator
 | 
			
		||||
{
 | 
			
		||||
	float mA, mB, mC, mP1, mP2;
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
	/* Convert formant freqencies and bandwidth into resonator difference equation coefficents
 | 
			
		||||
	 */
 | 
			
		||||
	void initResonator(
 | 
			
		||||
		int aFrequency,                       /* Frequency of resonator in Hz  */
 | 
			
		||||
		int aBandwidth,                      /* Bandwidth of resonator in Hz  */
 | 
			
		||||
		int aSamplerate);
 | 
			
		||||
 | 
			
		||||
	/* Convert formant freqencies and bandwidth into anti-resonator difference equation constants
 | 
			
		||||
	 */
 | 
			
		||||
	void initAntiresonator(
 | 
			
		||||
		int aFrequency,                       /* Frequency of resonator in Hz  */
 | 
			
		||||
		int aBandwidth,                      /* Bandwidth of resonator in Hz  */
 | 
			
		||||
		int aSamplerate);
 | 
			
		||||
 | 
			
		||||
	/* Set gain */
 | 
			
		||||
	void setGain(float aG);
 | 
			
		||||
 | 
			
		||||
	/* Generic resonator function */
 | 
			
		||||
	float resonate(float input);
 | 
			
		||||
 | 
			
		||||
	/* Generic anti-resonator function
 | 
			
		||||
	   Same as resonator except that a,b,c need to be set with initAntiresonator()
 | 
			
		||||
	   and we save inputs in p1/p2 rather than outputs.
 | 
			
		||||
	   There is currently only one of these - "mNasalZero"
 | 
			
		||||
	
 | 
			
		||||
	   Output = (mNasalZero.a * input) + (mNasalZero.b * oldin1) + (mNasalZero.c * oldin2) 
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
	float antiresonate(float input);
 | 
			
		||||
 | 
			
		||||
	resonator();
 | 
			
		||||
 | 
			
		||||
	~resonator();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -25,9 +25,8 @@ freely, subject to the following restrictions:
 | 
			
		|||
#define SOLOUD_SPEECH_H
 | 
			
		||||
 | 
			
		||||
#include "soloud.h"
 | 
			
		||||
#include "../src/audiosource/speech/darray.h"
 | 
			
		||||
#include "../src/audiosource/speech/klatt.h"
 | 
			
		||||
#include "../src/audiosource/speech/tts.h"
 | 
			
		||||
#include "darray.h"
 | 
			
		||||
#include "klatt.h"
 | 
			
		||||
 | 
			
		||||
namespace SoLoud
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue