mirror of
				https://github.com/cookiengineer/audacity
				synced 2025-10-30 17:23:51 +01:00 
			
		
		
		
	Add new files missed in previous commit
This commit is contained in:
		
							
								
								
									
										1097
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupv.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1097
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupv.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										164
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupv.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupv.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,164 @@ | ||||
| // | ||||
| //  cmupv.h | ||||
| //   | ||||
|  | ||||
| #ifndef __cmupv_h__ | ||||
| #define __cmupv_h__ | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" | ||||
| { | ||||
| #endif | ||||
|  | ||||
| // Protocol: The following is the order of calls with  | ||||
| //           optional calls [like_this], and {iteration in braces} | ||||
| //   pv_create | ||||
| //   optional: pv_set_blocksize | ||||
| //   optional: pv_set_fftsize | ||||
| //   pv_initialize | ||||
| //   repeat: {  | ||||
| //     optional: [pv_get_effective_pos] | ||||
| //     optional: [pv_set_ratio] | ||||
| //     pv_get_input_count | ||||
| //     pv_put_input (size must match result of pv_get_input_count) | ||||
| //     pv_get_output } | ||||
| //   pv_end | ||||
| // | ||||
| // Alternatively, you can use the "absolute" interface, where the | ||||
| // Phase_vocoder object tells you when it needs a frame of audio | ||||
| // and what output time corresponds to the center of the frame. | ||||
| // The "client" then returns the frame of samples and tells the | ||||
| // Phase_vocoder what hopsize was used. Of course, these callbacks | ||||
| // will demand samples for "future" output, so the client must know | ||||
| // how to find input samples for near-future points in the output: | ||||
| //   pv_create2 | ||||
| //   optional: pv_set_blocksize | ||||
| //   optional: pv_set_fftsize | ||||
| //   pv_initialize | ||||
| //   optional: pv_set_callback | ||||
| //   repeat: {  | ||||
| //     pv_get_output2 } ... during these calls, callback will get samples | ||||
|  | ||||
|  | ||||
| typedef void *Phase_vocoder; // a phase vocoder | ||||
| // the callback is given a sample count which is the output sample number | ||||
| // that will be at the center of the window. The callee should fill | ||||
| // samples with len samples from the input such that the center of the | ||||
| // len samples should be output at the given output sample count. | ||||
| // the hopsize should be returned. | ||||
| // Return value is the hopsize used (hop from previous input frame) | ||||
| typedef int (*Pv_callback)(long out_count, float *samples, int len,  | ||||
|                            void *rock); | ||||
|  | ||||
| // create a phase vocoder. Pass in function pointers to allocate | ||||
| // and deallocate memory, or NULL to use default malloc() | ||||
| // and free(): | ||||
| Phase_vocoder pv_create(void *(*mallocfn)(size_t), void (*freefn)(void *)); | ||||
|  | ||||
| // Use pv_create2() to use the "absolute" interface and pv_set_callback(). | ||||
| // As with pv_create, pass in custom malloc and free functions or NULL to | ||||
| // use default malloc() and free(). The callback is called to get input | ||||
| // frames, and the "rock" context parameter will be passed to the callback: | ||||
| Phase_vocoder pv_create2(void *(*mallocfn)(size_t), void (*freefn)(void *), | ||||
|                          Pv_callback callback, void *rock); | ||||
|  | ||||
| void pv_set_callback(Phase_vocoder x, Pv_callback callback, void *rock); | ||||
|  | ||||
| // call at the end of the program to free the memory | ||||
| void pv_end(Phase_vocoder *x); | ||||
|  | ||||
| // set output block size (call before computing first samples) | ||||
| // must be a power of 2 | ||||
| // Blocksize should be set beforehand and can't be changed | ||||
| // when program begins | ||||
| void pv_set_blocksize(Phase_vocoder x, int n); | ||||
|  | ||||
| // set FFT size, n must be power of 2 (call before computing | ||||
| // first samples) | ||||
| // FFT size should be set beforehand and can't be changed | ||||
| // when program begins | ||||
| void pv_set_fftsize(Phase_vocoder x, int n); | ||||
|  | ||||
| int round_log(int fftsize); //calculate the round num of log2_fft | ||||
|  | ||||
| // set ratio (call before pv_get_input_count()) | ||||
| // ratio is the stretch factor: >1 means output sound will be | ||||
| // longer than input sound | ||||
| void pv_set_ratio(Phase_vocoder x, float ratio); | ||||
|  | ||||
| // set synthesis hopsize, 'n' must be power of 2. | ||||
| // It's better to restrict syn_hopsize can only be | ||||
| // fftsize/2, fftsize/4, fftsize/8, fftsize/16. | ||||
| // Synthesis hopsize should be set beforehand and can't be | ||||
| // changed when program begins | ||||
| void pv_set_syn_hopsize(Phase_vocoder x, int n); | ||||
|  | ||||
| // initialize: allocate space for window, set default window, | ||||
| // allocate space for other parameters | ||||
| // Note that the user won't have the default window and don't | ||||
| // need to free it. | ||||
| void pv_initialize(Phase_vocoder x); | ||||
|  | ||||
| // set analysis window (if it's not called, default is Hanning window) | ||||
| // A copy of the window is made and managed by the Phase_vocoder, this | ||||
| // copy will be freed by the phase vocoder( by calling pv_end() ) | ||||
| // this function can be called many times, but only the newest window set | ||||
| // by the user is valid. | ||||
| void pv_set_ana_window(Phase_vocoder x, float *window); | ||||
|  | ||||
| // set synthesis window, same requirement as "pv_set_ana_window" | ||||
| void pv_set_syn_window(Phase_vocoder x, float *window); | ||||
|  | ||||
| #define PV_MODE_STANDARD 0 | ||||
| #define PV_MODE_PHASEFIX 1 | ||||
| #define PV_MODE_ROBOVOICE 2 | ||||
|  | ||||
| // set mode: to allow for variations in the algorithm | ||||
| //   mode values are: PV_MODE_STANDARD -- standard phase vocoder | ||||
| //   PV_MODE_PHASEFIX -- preserves the phase relationship between bins | ||||
| //      and their nearest peak. This is an experimental mode that may | ||||
| //      be refined in the future. It is inspired by Jean Laroche and | ||||
| //      Mark Dolson, "Phase-Vocoder: About this phasiness business" | ||||
| //   PV_MODE_ROBOVOICE, fixes the phases to create a deliberate | ||||
| //      modulation, generating a pitch due to the hopsize period. | ||||
| //      Thanks to M.C.Sharma for this idea. | ||||
| //   illegal mode values are ignored | ||||
| void pv_set_mode(Phase_vocoder x, int mode); | ||||
|  | ||||
| // allocate a window and initialize it with the window_type function | ||||
| // (see hann() and hamm() as example window_type functions) | ||||
| // caller becomes the owner of the result, so the owner should free | ||||
| // the window eventually. | ||||
| // Note the output is after normalized to make sure the sum of w1*w2 | ||||
| // equals to 1 rather than other constants. | ||||
| float *pv_window(Phase_vocoder x, float (*window_type)(double x)); | ||||
|  | ||||
| // inquire how many samples needed to compute next output | ||||
| int pv_get_input_count(Phase_vocoder x); | ||||
|  | ||||
| // get effective position of the next output sample  measured in  | ||||
| // samples of input. This may depend on the ratio (pv_set_ratio()). | ||||
| // Initially, the center of the analysis window will be input 0, | ||||
| // which will appear at output fftsize/2. There are ratio input | ||||
| // samples per output sample, so the input sample number corresponding | ||||
| // to output 0 is -ratio * fftsize / 2. | ||||
| double pv_get_effective_pos(Phase_vocoder x); | ||||
|  | ||||
| // send input samples - writes input to be stretched into | ||||
| // the phase vocoder. Phase vocoder saves as much of the | ||||
| // signal as needed so that input is always sequential. | ||||
| // note the "size" should be the output of pv_get_input_count(). | ||||
| void pv_put_input(Phase_vocoder x, int size, float *samples); | ||||
|  | ||||
| // get output samples: returns a pointer to n samples, where | ||||
| // n is the value from pv_set_block_size(). Pointer should | ||||
| // not be freed by the user. | ||||
| float *pv_get_output(Phase_vocoder x); | ||||
| // use pv_get_output2() if you used pv_create2(): | ||||
| float *pv_get_output2(Phase_vocoder x); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #endif /* defined(__cmupv_h__) */ | ||||
							
								
								
									
										69
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupvdbg.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupvdbg.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| /* cmupvdbg.c -- debug support for cmupv | ||||
|  * Roger B. Dannenberg | ||||
|  * Nov 2015 | ||||
|  */ | ||||
|  | ||||
| /* To see what data is going into the phase vocoder, write_pv_frame | ||||
|  * saves frames or buffers to disk as audio. | ||||
|  * If something is wrong with your applications delivery of analysis frames, | ||||
|  * probably most frames are wrong, so you should write, say, 10 initial | ||||
|  * files and look at them. Set MAX_FILES to 10 and MAX_SAVE to 10. Then, | ||||
|  * after running your program, use Audacity to open the 10 frames saved | ||||
|  * to disk: use the Files:Import:Audio command to load all 10 in one  | ||||
|  * command as different tracks. You should see 10 tracks, each containing | ||||
|  * one frame, shifted to the correct source time location. (If not, then | ||||
|  * find and fix the bug.) | ||||
|  * | ||||
|  * This function is also useful for printing other data, e.g. synthesis frames | ||||
|  * or output buffers. To get the most out of this, you should set the first | ||||
|  * parameter, zeros, to the absolute sample offset, e.g. if you want to view | ||||
|  * synthesis frames that are spaced with a 64 sample hop size, you should set | ||||
|  * zeros to 0, 64, 128, 192, ... so that when you view the files in Audacity, | ||||
|  * the samples will line up in time with each other and with the output file. | ||||
|  * | ||||
|  * You can display multiple frame types and lengths, so the prefix parameter | ||||
|  * allows you to effectively label the data. This prefix is used to construct | ||||
|  * the file name. | ||||
|  * | ||||
|  * MAX_FILES tells how many files to write. Because of padding, file writing | ||||
|  * is an N-squared operation, so only write initial frames if possible, but | ||||
|  * use a large number if you need to see everything. | ||||
|  * | ||||
|  * MAX_SAVE tells how many file *names* to use. Files are numbered, so we'll | ||||
|  * simply take the number modulo MAX_SAVE so that file names are reused and | ||||
|  * old files are overwritten. Use a large value of MAX_SAVE to save everything. | ||||
|  * Use 1 to get only the last frame. | ||||
|  */ | ||||
|  | ||||
| #include "stdio.h" | ||||
| #include "sndfile.h" | ||||
|  | ||||
|  | ||||
| #define MAX_FILES 10 | ||||
| #define MAX_SAVE 10 | ||||
| static int file_no = 0; | ||||
|  | ||||
|  | ||||
| void write_pv_frame(long zeros, float *frame, long fftsize, char *prefix) | ||||
| { | ||||
|     float z = 0; | ||||
|     char path[128]; | ||||
|     SF_INFO sfinfo; | ||||
|     SNDFILE *sf; | ||||
|     if (file_no >= MAX_FILES) return; | ||||
|     sprintf(path, "%s-%02d.wav", prefix, (file_no % MAX_SAVE) + 1); | ||||
|     sfinfo.frames = 0; | ||||
|     sfinfo.samplerate = 44100; | ||||
|     sfinfo.channels = 1; | ||||
|     sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; | ||||
|     sfinfo.sections = 0; | ||||
|     sfinfo.seekable = 0; | ||||
|     sf = sf_open(path, SFM_WRITE, &sfinfo); | ||||
|     for (long i = 0; i < zeros; i++) { | ||||
|         sf_writef_float(sf, &z, 1); | ||||
|     } | ||||
|     sf_writef_float(sf, frame, fftsize); | ||||
|     sf_close(sf); | ||||
|     printf("wrote %s, %ld zeros\n", path, zeros); | ||||
|     file_no++; | ||||
| } | ||||
							
								
								
									
										12
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupvdbg.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								lib-src/libnyquist/nyquist/cmupv/src/cmupvdbg.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| /* cmupvdbg.h -- cmupv debug function declarations */ | ||||
|  | ||||
| /* Normally, this function(s) are not called and the corresponding | ||||
|  * cmupvdbg.c need not be linked | ||||
|  */ | ||||
|  | ||||
| /* See comments in cmupvdbg.c and definitions of MAX_FILES and MAX_SAVE */ | ||||
|  | ||||
| /* write_pv_frame -- saves an array of floats as a sound file so you | ||||
|  * can see what is going into the phase vocoder | ||||
|  */ | ||||
| void write_pv_frame(long zeros, float *ana_frame, long fftsize, char *prefix); | ||||
							
								
								
									
										31
									
								
								lib-src/libnyquist/nyquist/cmupv/src/internal.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								lib-src/libnyquist/nyquist/cmupv/src/internal.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| // | ||||
| //  internal.c | ||||
| //   | ||||
| // | ||||
| // | ||||
| // | ||||
|  | ||||
| #define _USE_MATH_DEFINES | ||||
| #include "internal.h" | ||||
|  | ||||
| float hann(double x) | ||||
| { | ||||
|     return (float) (0.5 * (1.0 - cos(2 * M_PI * x))); | ||||
| } | ||||
|  | ||||
| float hamm(double x) | ||||
| { | ||||
|     return (float) (0.54 - 0.46 * cos(2 * M_PI * x)); | ||||
| } | ||||
|  | ||||
| void OneDimensionFFTshift(float vector[], int VectorLength) | ||||
| { | ||||
|     float temp; | ||||
|     int i; | ||||
|     for (i = 0; i <= VectorLength / 2 - 1; i++) | ||||
|     { | ||||
|         temp = vector[i]; | ||||
|         vector[i] = vector[VectorLength / 2 + i]; | ||||
|         vector[VectorLength / 2 + i] = temp; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										30
									
								
								lib-src/libnyquist/nyquist/cmupv/src/internal.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								lib-src/libnyquist/nyquist/cmupv/src/internal.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| // | ||||
| //  internal.h | ||||
| //   | ||||
| // | ||||
| // | ||||
| // | ||||
|  | ||||
| #ifndef _internal_h | ||||
| #define _internal_h | ||||
|  | ||||
| #ifndef _USE_MATH_DEFINES | ||||
| #define _USE_MATH_DEFINES 1 | ||||
| #endif | ||||
| #include <math.h> | ||||
|  | ||||
| // hanning window | ||||
| // 'x' is the independent variable of the window function. | ||||
| // 'x' is actually i/window_length, it's from 0 to 1-(1/window_length) | ||||
| float hann(double x); | ||||
|  | ||||
| // hamming window | ||||
| // 'x' is the independent variable of the window function. | ||||
| // 'x' is actually i/window_length, it's from 0 to 1-(1/window_length) | ||||
| float hamm(double x); | ||||
|  | ||||
| // FFT shift | ||||
| // VectorLength must be an even integer | ||||
| void OneDimensionFFTshift(float vector[],int VectorLength); | ||||
|  | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user