annotate src/sndstretch/sndstretch.c @ 3112:0d47d41b39ec

Remove debug g_print; the crasher has been identified.
author Tony Vroon <chainsaw@gentoo.org>
date Sun, 03 May 2009 22:47:38 +0100
parents 6bb0e52df3d6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
881
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1 // sndstretch.c
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
2 //
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
3 // sndstretch - algorithm for adjusting pitch and speed of s16le data
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
4 // Copyright (C) 2000 Florian Berger
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
5 // Email: florian.berger@jk.uni-linz.ac.at
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
6 //
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
7 // This program is free software; you can redistribute it and/or modify
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
8 // it under the terms of the GNU General Public License Version 2 as
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
9 // published by the Free Software Foundation;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
10 //
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
11 // This program is distributed in the hope that it will be useful,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
14 // GNU General Public License for more details.
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
15 //
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
16 // You should have received a copy of the GNU General Public License
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
17 // along with this program; if not, write to the Free Software
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
19 //
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
20 //
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
21
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
22 //#define DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
23
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
24 #include<stdio.h>
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
25 #include<stdlib.h>
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
26 #include<math.h>
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
27 #include"sndstretch.h"
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
28
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
29
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
30 static double _1_div_e = 0.367879441; // 1/e
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
31 static double _1_m_1_div_e = 0.632120558; // 1-1/e
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
32
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
33 #define RESMAX 65536
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
34 #define RESMAXVC 32768
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
35 #define LOG2RESMAX 16
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
36 #define LOG2RESMAXVC 15
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
37 static int _1_div_e_i = 24109; // 1/e * 2^LOG2RESMAX
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
38 static int _1_m_1_div_e_i = 41427; // 1-1/e * 2^LOG2RESMAX
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
39 static int _1_div_e_i_vc = 12055; // 1/e * 2^LOG2RESMAXVC
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
40 static int _1_m_1_div_e_i_vc = 28333; // sqrt(1-1/e^2) * 2^LOG2RESMAXVC
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
41 //static int _1_div_e_i = 12055; // 1/e * 2^LOG2RESMAX
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
42 //static int _1_m_1_div_e_i = 20713; // 1-1/e * 2^LOG2RESMAX
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
43
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
44
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
45 void InitScaleJob( ScaleJob * job )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
46 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
47 /* nothing to do */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
48 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
49
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
50
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
51 void InitStretchJob( StretchJob * job )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
52 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
53 job->is_initialized=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
54 job->snr_rest=0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
55 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
56
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
57
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
58 void InitPitchSpeedJob( PitchSpeedJob * job )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
59 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
60 job->ring_buff = (s16*)0; // init me = (s16*)0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
61 job->ring_buff_old = (s16*)0; // init me = (s16*)0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
62 job->buff_help = (s16*)0; // init me = (s16*)0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
63 job->ring_size = 1; // init me = 1
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
64 job->ring_size_old = 0; // init me = 0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
65 job->ring_pos_w = 0; // init me = 0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
66 job->ring_pos_r = 0; // init me = 0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
67 job->is_init = 0; // init me = 0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
68 job->speed_act = 0; // init me = 0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
69 job->pitch_act = 0; // init me = 0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
70 job->fade_shift_act = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
71 InitStretchJob(&(job->stretch_job));
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
72 InitScaleJob(&(job->scale_job));
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
73 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
74
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
75
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
76
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
77 void CleanupPitchSpeedJob( PitchSpeedJob * job )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
78 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
79 free(job->ring_buff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
80 free(job->ring_buff_old);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
81 free(job->buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
82 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
83
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
84
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
85
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
86 inline int ringpos( int pos, int size )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
87 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
88 while ( pos >= size ) pos-=size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
89 while ( pos < 0 ) pos+=size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
90 return( pos );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
91 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
92
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
93
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
94 void ringload( s16 * ringbuff, int ring_size, int pos, s16 *buffer, int size )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
95 /* put <size> samples to ring with size <ring_size> on position <pos> */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
96 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
97 int i,j;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
98
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
99 j=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
100 if( pos+size > ring_size ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
101 for( i=pos; i<ring_size; i++,j++ ) ringbuff[i]=buffer[j];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
102 for( i=0; i<size-ring_size+pos; i++,j++ ) ringbuff[i]=buffer[j];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
103 }else{
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
104 for( i=pos; i<size+pos; i++,j++ ) ringbuff[i]=buffer[j];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
105 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
106 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
107
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
108
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
109 void ringcopy( s16 * src_ring, int src_size, int src_from, int src_to,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
110 s16 * dest_ring, int dest_size, int dest_pos )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
111 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
112 int is,id;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
113
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
114 is=src_from; id=dest_pos;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
115 while( is!=src_to ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
116 dest_ring[id]=src_ring[is];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
117 is=ringpos(is+1,src_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
118 id=ringpos(id+1,dest_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
119 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
120 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
121
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
122
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
123 void ringload_IIR_1_div_e_echo_d( s16 * ringbuff, int ring_size, int pos, s16 *buffer, int size , int delay)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
124 /* put <size> samples to ring with size <ring_size> on position <pos> */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
125 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
126 int i,p1,p2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
127
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
128 p1=pos, p2=ringpos(p1-delay, ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
129 for( i=0; i<size; i++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
130 ringbuff[p1] =(s16)( (double)buffer[i]*_1_m_1_div_e + (double)ringbuff[p2]*_1_div_e );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
131 p1++; if(p1>=ring_size) p1-=ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
132 p2++; if(p2>=ring_size) p2-=ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
133 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
134 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
135
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
136
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
137 void ringload_IIR_1_div_e_echo_i( s16 * ringbuff, int ring_size, int pos, s16 *buffer, int size , int delay)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
138 /* put <size> samples to ring with size <ring_size> on position <pos> */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
139 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
140 int i,p1,p2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
141
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
142 p1=pos, p2=ringpos(p1-delay, ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
143 for( i=0; i<size; i++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
144 ringbuff[p1] =(s16)( (
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
145 _1_m_1_div_e_i * buffer[i] +
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
146 _1_div_e_i * ringbuff[p2]
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
147 ) >> LOG2RESMAX );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
148 p1++; if(p1>=ring_size) p1-=ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
149 p2++; if(p2>=ring_size) p2-=ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
150 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
151 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
152
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
153
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
154 void ringload_IIR_1_div_e_echo_i_vc( s16 * ringbuff, int ring_size, int pos, s16 *buffer, int size , int delay)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
155 /* put <size> samples to ring with size <ring_size> on position <pos> */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
156 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
157 int i,p1,p2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
158 int actval;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
159
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
160 p1=pos, p2=ringpos(p1-delay, ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
161 for( i=0; i<size; i++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
162 /* ringbuff[p1] =(s16)( (
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
163 _1_m_1_div_e_i_vc * buffer[i] +
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
164 _1_div_e_i_vc * ringbuff[p2]
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
165 ) >> LOG2RESMAXVC );*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
166 actval = _1_m_1_div_e_i_vc * buffer[i] +
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
167 _1_div_e_i_vc * ringbuff[p2];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
168 /* prevent overflow */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
169 if( actval > (int)0x3FFFFFFF ) actval=(int)0x3FFFFFFF;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
170 if( actval < (int)0xC0000000 ) actval=(int)0xC0000000;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
171 ringbuff[p1] = actval >> LOG2RESMAXVC;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
172 p1++; if(p1>=ring_size) p1-=ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
173 p2++; if(p2>=ring_size) p2-=ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
174 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
175 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
176
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
177
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
178 /*void ringget ( s16 * ringbuff, int ring_size, int pos, s16 *buffer, int size )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
179 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
180 int i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
181
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
182 if( pos+size > ring_size ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
183 for( i=pos; i<ring_size; i++ ) buffer[i]=ringbuff[i];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
184 for( i=0; i<size-ring_size+pos; i++ ) buffer[i]=ringbuff[i];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
185 }else{
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
186 for( i=pos; i<size+pos; i++ ) buffer[i]=ringbuff[i];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
187 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
188 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
189 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
190
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
191 //int sndstretch( // not optimized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
192 int sndstretch_not_optimized(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
193 /* stretches the sound (not changing pitch !!!) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
194 /* returns number of output samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
195 /* chnr simply gives multiples of chnr as snr_prod */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
196 s16 * buffer, int buff_size, /* ring buffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
197 int pos_init, /* only initial pos in ringbuffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
198 int snr_i, int snr_o, /* enlarge - spec */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
199 int chnr, /* # of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
200 s16 * outbuff, /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
201 int * out_prod, /* # of output-samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
202 int snr_proc, /* # of in-samples to process */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
203 int initialize /* bool */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
204 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
205 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
206 static int is_initialized=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
207 static int snr_o_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
208 static int snr_i_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
209 static int snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
210 /* static int snr_offs; */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
211 static int pos_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
212 static int dsnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
213 /* static int p1,p2; */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
214 static double snr_rest=0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
215
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
216 int snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
217 double snr_d;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
218
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
219 int i,p1,p2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
220 double fade_in, fade_out;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
221 double outd;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
222
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
223 /* s16 * outbuff; */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
224
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
225 /* reset */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
226 if( !is_initialized || initialize ||
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
227 snr_i!=snr_i_act || snr_o!=snr_o_act ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
228
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
229 snr_rest = 0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
230 snr_o_prod = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
231 snr_i_act = snr_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
232 snr_o_act = snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
233 dsnr = snr_o_act-snr_i_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
234 pos_act = pos_init;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
235
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
236 is_initialized = 1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
237
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
238 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
239
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
240 /* fprintf(stderr,"pos_act=%d\n",pos_act);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
241 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
242 snr_d = (double)snr_proc*(double)snr_o_act/(double)snr_i_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
243 + snr_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
244 snr = (int) (snr_d) / 2 * 2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
245 snr_rest = snr_d - (double)snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
246
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
247 /* fprintf(stderr,"snr=%d\n",snr);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
248 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
249 /* outbuff=malloc(snr*sizeof(s16));
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
250 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
251 /* produce snr samples */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
252 i=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
253 do {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
254 if( snr_o_prod == snr_o_act ) {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
255 snr_o_prod=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
256 /* fprintf(stderr,"!!!!!!!!!!!!!!!!!!!!!!!!!! dsnr = %d\n",dsnr);*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
257 pos_act = ringpos( pos_act-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
258 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
259 for ( ; snr_o_prod < snr_o_act && i<snr ; snr_o_prod++,i++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
260 p1=pos_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
261 p2=ringpos( p1-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
262 // p3=ringpos( p2-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
263 // p4=ringpos( p3-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
264 // p2=ringpos( p1-abs(dsnr), buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
265 // p3=ringpos( p2-abs(dsnr), buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
266 // p4=ringpos( p3-abs(dsnr), buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
267 fade_in = (double)snr_o_prod/(double)snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
268 fade_out = 1.0-fade_in;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
269 // fade1 = (dsnr>0)?fade_out:fade_in;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
270 // fade2 = (dsnr>0)?fade_in:fade_out;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
271 outd = (
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
272 (double)buffer[p1] * fade_out /* fade out */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
273 + (double)buffer[p2] * fade_in /* fade in */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
274 // +( 0.67 * (double)buffer[p1] /* fade out for lengthen */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
275 // + 0.24 * (double)buffer[p2] /* fade out */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
276 // + 0.09 * (double)buffer[p3]) * fade_out /* fade out */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
277 // +( 0.67 * (double)buffer[p2] /* fade in */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
278 // + 0.24 * (double)buffer[p3] /* fade in */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
279 // + 0.09 * (double)buffer[p4]) * fade_in /* fade in */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
280 );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
281 outbuff[i] = outd+0.5;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
282 pos_act=ringpos( pos_act+1, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
283 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
284 } while( i<snr );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
285
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
286 /* fwrite( outbuff, sizeof(s16), snr, stdout );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
287 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
288 /* free(outbuff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
289 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
290 *out_prod = snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
291
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
292 /* fprintf(stderr,"snr = %d\n",snr);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
293 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
294 return( *out_prod );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
295 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
296
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
297
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
298 int sndstretch( // optimized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
299 //int sndstretch_optimized( // optimized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
300 /* stretches the sound (not changing pitch !!!) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
301 /* returns number of output samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
302 /* chnr simply gives multiples of chnr as snr_prod */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
303 s16 * buffer, int buff_size, /* ring buffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
304 int pos_init, /* only initial pos in ringbuffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
305 int snr_i, int snr_o, /* enlarge - spec */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
306 int chnr, /* # of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
307 s16 * outbuff, /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
308 int * out_prod, /* # of output-samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
309 int snr_proc, /* # of in-samples to process */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
310 int initialize /* bool */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
311 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
312 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
313 static int is_initialized=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
314 static int snr_o_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
315 static int snr_i_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
316 static int snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
317 static int pos_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
318 static int dsnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
319 static double snr_rest=0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
320
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
321 static int _RESMAX_div_max, _RESMAX_mod_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
322 static int fade_in_i, fade_out_i, fade_rest_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
323
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
324 /* not necessarily static */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
325 static int snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
326 static double snr_d;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
327 static int i,p2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
328
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
329 /* reset */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
330 if( !is_initialized || initialize ||
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
331 snr_i!=snr_i_act || snr_o!=snr_o_act ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
332
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
333 snr_rest = 0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
334 snr_o_prod = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
335 snr_i_act = snr_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
336 snr_o_act = snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
337 dsnr = snr_o_act-snr_i_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
338 pos_act = pos_init;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
339
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
340 is_initialized = 1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
341
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
342 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
343
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
344 snr_d = (double)snr_proc*(double)snr_o_act/(double)snr_i_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
345 + snr_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
346 snr = (int) (snr_d) / 2 * 2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
347 snr_rest = snr_d - (double)snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
348
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
349 /* produce snr samples */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
350 i=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
351 do {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
352 if( snr_o_prod == snr_o_act ) {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
353 snr_o_prod=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
354 pos_act = ringpos( pos_act-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
355 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
356 fade_in_i = RESMAX*((double)snr_o_prod/(double)snr_o_act);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
357 fade_out_i = RESMAX-fade_in_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
358 fade_rest_i= (RESMAX*snr_o_prod)%snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
359 _RESMAX_div_max=RESMAX/snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
360 _RESMAX_mod_max=RESMAX%snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
361 p2=ringpos( pos_act-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
362 for ( ; snr_o_prod < snr_o_act && i<snr ; snr_o_prod++,i++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
363 fade_in_i +=_RESMAX_div_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
364 fade_out_i -=_RESMAX_div_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
365 fade_rest_i+=_RESMAX_mod_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
366 if(fade_rest_i>snr_o_act){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
367 fade_rest_i-=snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
368 fade_in_i++;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
369 fade_out_i--;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
370 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
371 outbuff[i] = (s16)( (
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
372 + (int)buffer[pos_act] * fade_out_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
373 + (int)buffer[p2] * fade_in_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
374 ) >> LOG2RESMAX );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
375 pos_act++; if(pos_act>=buff_size) pos_act-=buff_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
376 p2++; if(p2 >=buff_size) p2 -=buff_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
377 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
378 } while( i<snr );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
379
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
380 *out_prod = snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
381
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
382 return( *out_prod );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
383 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
384
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
385
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
386 int sndstretch_job( // optimized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
387 //int sndstretch_optimized( // optimized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
388 /* stretches the sound (not changing pitch !!!) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
389 /* returns number of output samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
390 /* chnr simply gives multiples of chnr as snr_prod */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
391 s16 * buffer, int buff_size, /* ring buffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
392 int pos_init, /* only initial pos in ringbuffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
393 int snr_i, int snr_o, /* enlarge - spec */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
394 int chnr, /* # of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
395 s16 * outbuff, /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
396 int * out_prod, /* # of output-samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
397 int snr_proc, /* # of in-samples to process */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
398 int initialize, /* bool */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
399 StretchJob * job
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
400 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
401 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
402 /* static int is_initialized=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
403 static int snr_o_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
404 static int snr_i_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
405 static int snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
406 static int pos_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
407 static int dsnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
408 static double snr_rest=0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
409
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
410 static int _RESMAX_div_max, _RESMAX_mod_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
411 static int fade_in_i, fade_out_i, fade_rest_i;*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
412
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
413 /* not necessarily static */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
414 static int snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
415 static double snr_d;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
416 static int i,p2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
417
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
418 #define is_initialized (job->is_initialized )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
419 #define snr_o_prod (job->snr_o_prod )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
420 #define snr_i_act (job->snr_i_act )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
421 #define snr_o_act (job->snr_o_act )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
422 #define pos_act (job->pos_act )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
423 #define dsnr (job->dsnr )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
424 #define snr_rest (job->snr_rest )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
425 #define _RESMAX_div_max (job->_RESMAX_div_max)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
426 #define _RESMAX_mod_max (job->_RESMAX_mod_max)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
427 #define fade_in_i (job->fade_in_i )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
428 #define fade_out_i (job->fade_out_i )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
429 #define fade_rest_i (job->fade_rest_i )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
430
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
431 /* reset */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
432 if( !is_initialized || initialize ||
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
433 snr_i!=snr_i_act || snr_o!=snr_o_act ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
434
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
435 snr_rest = 0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
436 snr_o_prod = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
437 snr_i_act = snr_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
438 snr_o_act = snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
439 dsnr = snr_o_act-snr_i_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
440 pos_act = pos_init;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
441
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
442 is_initialized = 1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
443
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
444 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
445
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
446 snr_d = (double)snr_proc*(double)snr_o_act/(double)snr_i_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
447 + snr_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
448 snr = (int) (snr_d) / 2 * 2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
449 snr_rest = snr_d - (double)snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
450
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
451 /* produce snr samples */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
452 i=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
453 do {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
454 if( snr_o_prod == snr_o_act ) {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
455 snr_o_prod=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
456 pos_act = ringpos( pos_act-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
457 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
458 fade_in_i = RESMAX*((double)snr_o_prod/(double)snr_o_act);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
459 fade_out_i = RESMAX-fade_in_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
460 fade_rest_i= (RESMAX*snr_o_prod)%snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
461 _RESMAX_div_max=RESMAX/snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
462 _RESMAX_mod_max=RESMAX%snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
463 p2=ringpos( pos_act-dsnr, buff_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
464 for ( ; snr_o_prod < snr_o_act && i<snr ; snr_o_prod++,i++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
465 fade_in_i +=_RESMAX_div_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
466 fade_out_i -=_RESMAX_div_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
467 fade_rest_i+=_RESMAX_mod_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
468 if(fade_rest_i>snr_o_act){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
469 fade_rest_i-=snr_o_act;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
470 fade_in_i++;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
471 fade_out_i--;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
472 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
473 outbuff[i] = (s16)( (
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
474 + (int)buffer[pos_act] * fade_out_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
475 + (int)buffer[p2] * fade_in_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
476 ) >> LOG2RESMAX );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
477 pos_act++; if(pos_act>=buff_size) pos_act-=buff_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
478 p2++; if(p2 >=buff_size) p2 -=buff_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
479 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
480 } while( i<snr );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
481
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
482 *out_prod = snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
483
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
484 return( *out_prod );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
485
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
486 #undef is_initialized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
487 #undef snr_o_prod
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
488 #undef snr_i_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
489 #undef snr_o_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
490 #undef pos_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
491 #undef dsnr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
492 #undef snr_rest
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
493 #undef _RESMAX_div_max
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
494 #undef _RESMAX_mod_max
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
495 #undef fade_in_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
496 #undef fade_out_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
497 #undef fade_rest_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
498 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
499
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
500
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
501 //int sndscale(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
502 int sndscale_not_optimized(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
503 /* rescales the sound (including pitch) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
504 /* returns number of output samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
505 s16 * buffer, /* ring buffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
506 int snr_i, int snr_o, /* enlarge - spec */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
507 int chnr, /* # of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
508 s16 * outbuff, /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
509 int * out_prod, /* # of output-samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
510 int snr_proc, /* # of in-samples to process */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
511 /* must be manifold of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
512 int initialize /* bool */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
513 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
514 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
515 static s16 last_samp[10]; /* 10 channels maximum ;) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
516 static double pos_d = 0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
517
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
518 int snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
519 int pos1, pos2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
520 s16 samp1, samp2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
521 int index1, index2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
522 int ch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
523 double ds;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
524 double ratio1, ratio2, outd;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
525
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
526
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
527 if ( initialize ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
528 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
529 last_samp[ch] = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
530 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
531 pos_d = 0.0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
532 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
533
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
534 ds = 1.0*(double)snr_i/(double)snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
535
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
536 /* fprintf(stderr,"ds=%f\n",ds); */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
537 /* fprintf(stderr,"pos_d =%f\n",pos_d);*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
538
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
539 /* produce proper amount of samples */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
540 for( snr=0 ; pos_d < snr_proc/chnr-1 ; pos_d+=ds ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
541
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
542 pos1 = (int)floor(pos_d);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
543 pos2 = pos1+1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
544 ratio1 = 1-pos_d+floor(pos_d);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
545 ratio2 = pos_d-floor(pos_d);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
546
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
547 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
548
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
549 index1 = pos1*chnr+ch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
550 index2 = pos2*chnr+ch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
551
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
552 samp1 = (pos_d<0) ? last_samp[ch] : buffer[index1] ;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
553 samp2 = buffer[index2];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
554
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
555 outd = (double)samp1 * ratio1
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
556 + (double)samp2 * ratio2 ;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
557
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
558 outbuff[snr+ch] = outd+0.5;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
559
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
560 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
561
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
562 snr+=chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
563
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
564 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
565
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
566 pos_d -= (double)(snr_proc/chnr);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
567
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
568 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
569 last_samp[ch] = buffer[snr_proc-chnr+ch];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
570 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
571
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
572 *out_prod = snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
573
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
574 /* fprintf(stderr,"snr = %d\n",snr);*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
575
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
576 /* last_samp = buffer[snr_proc-1]; */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
577
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
578 return( snr );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
579 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
580
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
581
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
582
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
583 int sndscale( //optimized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
584 //int sndscale2p_optimized(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
585 /* rescales the sound (including pitch) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
586 /* returns number of output samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
587 s16 * buffer, /* ring buffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
588 int snr_i, int snr_o, /* enlarge - spec snr_o must not exceed RESMAX */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
589 int chnr, /* # of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
590 s16 * outbuff, /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
591 int * out_prod, /* # of output-samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
592 int snr_proc, /* # of in-samples to process */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
593 /* must be manifold of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
594 int initialize /* bool */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
595 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
596 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
597 static s16 last_samp[10]; /* 10 channels maximum ;) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
598 static int pos_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
599
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
600 static int snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
601 static int pos1, pos2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
602 static int ch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
603 static int ratio1_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
604 static int ds_li, ds_li_c, ds_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
605 static int snr_proc_m_chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
606
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
607
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
608 if ( initialize ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
609 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
610 last_samp[ch] = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
611 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
612 pos1 = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
613 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
614
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
615 ds_li = snr_i/snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
616 ds_li_c = ds_li*chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
617 ds_rest = snr_i%snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
618
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
619 snr_proc_m_chnr = snr_proc-chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
620 for( snr=0 ; pos1 < snr_proc_m_chnr ; pos1+=ds_li_c ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
621
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
622 pos2 = pos1+chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
623 ratio1_i = snr_o-pos_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
624
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
625 if (pos1<0){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
626 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
627 outbuff[snr+ch] = (s16)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
628 ( ( (int)last_samp[ch] * ratio1_i +
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
629 (int)buffer[pos2+ch] * pos_rest ) / snr_o ) ;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
630 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
631 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
632 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
633 outbuff[snr+ch] = (s16)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
634 ( ( (int)buffer[pos1+ch] * ratio1_i +
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
635 (int)buffer[pos2+ch] * pos_rest ) / snr_o ) ;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
636 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
637 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
638
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
639 snr+=chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
640
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
641 pos_rest+=ds_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
642 if( pos_rest>=snr_o ){ pos_rest-=snr_o; pos1+=chnr; }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
643 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
644
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
645 pos1 -= snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
646
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
647 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
648 last_samp[ch] = buffer[snr_proc-chnr+ch];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
649 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
650
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
651 *out_prod = snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
652
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
653 return( snr );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
654 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
655
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
656
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
657
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
658 int sndscale_job( //optimized
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
659 //int sndscale2p_optimized(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
660 /* rescales the sound (including pitch) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
661 /* returns number of output samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
662 s16 * buffer, /* ring buffer */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
663 int snr_i, int snr_o, /* enlarge - spec snr_o must not exceed RESMAX */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
664 int chnr, /* # of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
665 s16 * outbuff, /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
666 int * out_prod, /* # of output-samples produced */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
667 int snr_proc, /* # of in-samples to process */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
668 /* must be manifold of channels */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
669 int initialize, /* bool */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
670 ScaleJob * job
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
671 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
672 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
673 /* static s16 * last_samp;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
674 static int pos_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
675
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
676 static int snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
677 static int pos1, pos2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
678 static int ch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
679 static int ratio1_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
680 static int ds_li, ds_li_c, ds_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
681 static int snr_proc_m_chnr;*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
682
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
683 #define last_samp job->last_samp
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
684 #define pos_rest job->pos_rest
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
685 #define snr job->snr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
686 #define pos1 job->pos1
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
687 #define pos2 job->pos2
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
688 #define ch job->ch
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
689 #define ratio1_i job->ratio1_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
690 #define ds_li job->ds_li
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
691 #define ds_li_c job->ds_li_c
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
692 #define ds_rest job->ds_rest
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
693 #define snr_proc_m_chnr job->snr_proc_m_chnr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
694
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
695 if ( initialize ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
696 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
697 last_samp[ch] = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
698 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
699 pos1 = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
700 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
701
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
702 ds_li = snr_i/snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
703 ds_li_c = ds_li*chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
704 ds_rest = snr_i%snr_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
705
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
706 snr_proc_m_chnr = snr_proc-chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
707 for( snr=0 ; pos1 < snr_proc_m_chnr ; pos1+=ds_li_c ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
708
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
709 pos2 = pos1+chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
710 ratio1_i = snr_o-pos_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
711
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
712 if (pos1<0){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
713 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
714 outbuff[snr+ch] = (s16)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
715 ( ( (int)last_samp[ch] * ratio1_i +
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
716 (int)buffer[pos2+ch] * pos_rest ) / snr_o ) ;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
717 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
718 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
719 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
720 outbuff[snr+ch] = (s16)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
721 ( ( (int)buffer[pos1+ch] * ratio1_i +
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
722 (int)buffer[pos2+ch] * pos_rest ) / snr_o ) ;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
723 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
724 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
725
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
726 snr+=chnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
727
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
728 pos_rest+=ds_rest;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
729 if( pos_rest>=snr_o ){ pos_rest-=snr_o; pos1+=chnr; }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
730 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
731
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
732 pos1 -= snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
733
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
734 for( ch=0; ch<chnr; ch++ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
735 last_samp[ch] = buffer[snr_proc-chnr+ch];
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
736 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
737
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
738 *out_prod = snr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
739
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
740 return( snr );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
741
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
742 #undef last_samp
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
743 #undef pos_rest
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
744 #undef snr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
745 #undef pos1
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
746 #undef pos2
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
747 #undef ch
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
748 #undef ratio1_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
749 #undef ds_li
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
750 #undef ds_li_c
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
751 #undef ds_rest
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
752 #undef snr_proc_m_chnr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
753 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
754
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
755
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
756
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
757 int snd_pitch_speed(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
758 /* input */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
759 s16 *buff_i, int channels, int snr_proc,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
760 /* algorihm parameters */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
761 int initialize, double pitch, double speed, int fade_shift,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
762 /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
763 s16 * buff_o, int * snr_produced
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
764 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
765 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
766 static s16 * ring_buff = (s16*)0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
767 static s16 * ring_buff_old = (s16*)0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
768 static s16 * buff_help = (s16*)0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
769 static int ring_size = 1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
770 static int ring_size_old = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
771 static int ring_pos_w = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
772 static int ring_pos_r = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
773 static int snr_scale_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
774 static int snr_scale_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
775 static int snr_stretch_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
776 static int snr_stretch_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
777 static int snr_proc_scale;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
778 static int snr_proc_stretch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
779 static int is_init = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
780 static int dsnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
781 static double speed_act = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
782 static double pitch_act = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
783 static double fade_shift_act = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
784
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
785 int snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
786 double speed_eff;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
787 double pitch_eff;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
788 int scaling_first;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
789 int snr_stretching_i_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
790 int snr_stretching_o_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
791
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
792 // int channels = 2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
793 int init_me = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
794
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
795 speed_eff = speed/pitch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
796 pitch_eff = pitch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
797
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
798 scaling_first=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
799 // if( pitch > 1.0 ) scaling_first=0; else scaling_first=1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
800
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
801 if ( !is_init || initialize || speed!=speed_act || pitch!=pitch_act ||
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
802 fade_shift!=fade_shift_act ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
803
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
804 if( !is_init || initialize ) init_me=1; else init_me=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
805
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
806 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
807 fprintf(stderr,"snd_stretch_scale - init - pitch:%f, speed:%f\n",pitch,speed);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
808 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
809
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
810 speed_act = speed;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
811 pitch_act = pitch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
812 fade_shift_act = fade_shift;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
813
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
814 // if (ring_buff!=0) free(ring_buff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
815 // if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
816
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
817 if (initialize != -1){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
818
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
819 dsnr = fade_shift;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
820 // dsnr = 1764; // 25Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
821 // dsnr = 1536; // 30Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
822 // dsnr = 1102; // 40Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
823 // dsnr = 882; // 50Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
824
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
825 if( scaling_first ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
826 snr_stretching_i_max = ceil((double)snr_proc/pitch_act);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
827 snr_stretching_i_max += channels-1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
828 snr_stretching_i_max /= channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
829 snr_stretching_i_max *= channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
830 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
831 snr_stretching_i_max = (snr_proc+channels-1)/channels*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
832 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
833
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
834 snr_stretching_o_max =
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
835 ceil((double)snr_stretching_i_max / speed_eff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
836 snr_stretching_o_max =
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
837 (snr_stretching_o_max+channels-1)/channels*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
838
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
839 ring_size = snr_stretching_o_max /* for reading */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
840 + dsnr*channels /* for grabbing back */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
841 + dsnr*channels /* for readpos catching */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
842 /* up with writepos */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
843 + 2*dsnr*channels ; /* for 2 pre - echos */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
844 // ring_size = snr_stretching_o_max+3*dsnr*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
845
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
846 if( ring_size <= ring_size_old ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
847 ring_size = ring_size_old;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
848 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
849 fprintf(stderr," ring_size = %d \n",ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
850 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
851 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
852 /* if (ring_buff!=0) free(ring_buff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
853 if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
854 ring_buff = calloc( ring_size, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
855 buff_help = calloc( 65536, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
856 ring_pos_r = 0;*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
857 if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
858 ring_buff_old = ring_buff;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
859 ring_buff = calloc( ring_size, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
860 buff_help = calloc( 65536, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
861 if (ring_buff_old!=0) ringcopy( ring_buff, ring_size, ring_pos_r, ring_pos_w, ring_buff_old, ring_size_old, ring_pos_r );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
862 if (ring_buff_old!=0) free(ring_buff_old);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
863 // ring_pos_w=ringpos(ring_pos_w+ring_size_old,ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
864 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
865 fprintf(stderr," %d s16-samples reserved\n",ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
866 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
867 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
868
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
869 ring_pos_w =
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
870 ringpos( ring_pos_r + /* base */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
871 dsnr*channels /* for grabing back */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
872 // dsnr*2 /* for grabing back */ // why *2
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
873 , ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
874 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
875 fprintf(stderr," ring_pos_w = %d\n",ring_pos_w);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
876 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
877 ring_pos_w = (ring_pos_w+(channels-1))/channels*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
878
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
879 ring_size_old = ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
880
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
881 is_init = 1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
882
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
883 } else { /* initialize == -1 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
884 if (ring_buff!=0) free(ring_buff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
885 if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
886 /* buffers are released -> leave the function */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
887 return 0; /* !!! sloppy */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
888 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
889
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
890 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
891
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
892 if ( fabs(speed_eff-1.0)>0.001 ){ /*
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
893 0.001 ?!
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
894 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
895 this should be examined to the limits
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
896 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
897 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
898 snr_stretch_i = (double)dsnr/(1.0/speed_eff-1.0);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
899 snr_stretch_o = fabs(snr_stretch_i + dsnr);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
900 snr_stretch_i = abs(snr_stretch_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
901 // fprintf(stderr,"snd_stretch_scale - snr_str_i=%d\n",snr_stretch_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
902 // fprintf(stderr,"snd_stretch_scale - snr_str_o=%d\n",snr_stretch_o);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
903 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
904 snr_stretch_i = 10;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
905 snr_stretch_o = 10;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
906 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
907
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
908 if ( pitch_eff!=1.0 ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
909 snr_scale_i = (double)dsnr/(1.0/pitch_eff-1.0);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
910 snr_scale_o = fabs(snr_scale_i + dsnr);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
911 snr_scale_i = abs(snr_scale_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
912 if( 1 /* optimized version doesnt support all scaling */ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
913 if( snr_scale_o > 65536 ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
914 snr_scale_i = (int)((double)snr_scale_i*((double)65536/(double)snr_scale_o)+0.5);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
915 snr_scale_o = 65536;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
916 // make sure that snr_o for sndscale wont exceed 2^16
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
917 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
918 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
919 // fprintf(stderr,"snd_stretch_scale - snr_sc_i=%d\n",snr_stretch_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
920 // fprintf(stderr,"snd_stretch_scale - snr_sc_o=%d\n",snr_stretch_o);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
921 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
922 // fprintf(stderr,"snd_stretch_scale - snr_scale_i=snr_scale_o=10\n");
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
923 snr_scale_i = 65536;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
924 snr_scale_o = 65536;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
925 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
926
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
927 if( 0/*scaling_first*/ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
928
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
929 snr_proc_scale = snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
930 sndscale ( buff_i,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
931 snr_scale_i, snr_scale_o, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
932 buff_help, &snr_prod, snr_proc_scale, init_me );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
933 /* buff_o, &snr_prod, snr_proc_scale, 0 ); */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
934
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
935 if( speed_eff!=1.0 ){ /* add echo only when really stretching */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
936 ringload_IIR_1_div_e_echo_i( ring_buff, ring_size, ring_pos_w, buff_help, snr_prod, dsnr*channels );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
937 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
938 ringload( ring_buff, ring_size, ring_pos_w, buff_help, snr_prod );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
939 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
940 ring_pos_w = ringpos( ring_pos_w+snr_prod, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
941
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
942 snr_proc_stretch = snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
943 sndstretch ( ring_buff, ring_size, ring_pos_r,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
944 snr_stretch_i*channels, snr_stretch_o*channels, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
945 buff_o, &snr_prod, snr_proc_stretch, init_me );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
946
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
947 ring_pos_r = ringpos( ring_pos_r+snr_prod, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
948
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
949 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
950
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
951 // fprintf(stderr,"sndstretch: ring_pos_r = %d\n",ring_pos_r);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
952 // fprintf(stderr,"sndstretch: ring_pos_w = %d\n\n",ring_pos_w);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
953 snr_prod = snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
954 if( speed_eff!=1.0 ){ /* add echo only when really stretching */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
955 ringload_IIR_1_div_e_echo_i( ring_buff, ring_size, ring_pos_w, buff_i, snr_proc, dsnr*channels );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
956 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
957 ringload( ring_buff, ring_size, ring_pos_w, buff_i, snr_proc );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
958 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
959 ring_pos_w = ringpos( ring_pos_w+snr_proc, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
960
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
961 snr_proc_stretch = snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
962 sndstretch ( ring_buff, ring_size, ring_pos_r,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
963 snr_stretch_i*channels, snr_stretch_o*channels, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
964 buff_help, &snr_prod, snr_proc_stretch, init_me );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
965
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
966 ring_pos_r = ringpos( ring_pos_r+snr_prod, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
967
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
968 snr_proc_scale = snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
969 // fprintf(stderr,"snr_scale_i, snr_scale_o = %d,%d\n",snr_scale_i, snr_scale_o);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
970 sndscale ( buff_help,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
971 snr_scale_i, snr_scale_o, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
972 buff_o, &snr_prod, snr_proc_scale, init_me );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
973
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
974 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
975
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
976 *snr_produced = snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
977
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
978 return snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
979 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
980
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
981
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
982 int snd_pitch_speed_job(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
983 /* input */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
984 s16 *buff_i, int channels, int snr_proc,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
985 /* algorihm parameters */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
986 int initialize, double pitch, double speed, int fade_shift,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
987 /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
988 s16 * buff_o, int * snr_produced, PitchSpeedJob * job,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
989 int vol_corr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
990 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
991 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
992 /* static s16 * ring_buff = (s16*)0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
993 static s16 * ring_buff_old = (s16*)0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
994 static s16 * buff_help = (s16*)0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
995 static int ring_size = 1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
996 static int ring_size_old = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
997 static int ring_pos_w = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
998 static int ring_pos_r = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
999 static int snr_scale_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1000 static int snr_scale_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1001 static int snr_stretch_i;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1002 static int snr_stretch_o;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1003 static int snr_proc_scale;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1004 static int snr_proc_stretch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1005 static int is_init = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1006 static int dsnr;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1007 static double speed_act = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1008 static double pitch_act = 0;*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1009
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1010 int snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1011 double speed_eff;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1012 double pitch_eff;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1013 int scaling_first;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1014 int snr_stretching_i_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1015 int snr_stretching_o_max;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1016
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1017 // int channels = 2;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1018 int init_me = 0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1019
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1020 #define ring_buff job->ring_buff
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1021 #define ring_buff_old job->ring_buff_old
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1022 #define buff_help job->buff_help
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1023 #define ring_size job->ring_size
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1024 #define ring_size_old job->ring_size_old
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1025 #define ring_pos_w job->ring_pos_w
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1026 #define ring_pos_r job->ring_pos_r
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1027 #define snr_scale_i job->snr_scale_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1028 #define snr_scale_o job->snr_scale_o
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1029 #define snr_stretch_i job->snr_stretch_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1030 #define snr_stretch_o job->snr_stretch_o
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1031 #define snr_proc_scale job->snr_proc_scale
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1032 #define snr_proc_stretch job->snr_proc_stretch
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1033 #define is_init job->is_init
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1034 #define dsnr job->dsnr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1035 #define speed_act job->speed_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1036 #define pitch_act job->pitch_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1037 #define fade_shift_act job->fade_shift_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1038
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1039 speed_eff = speed/pitch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1040 pitch_eff = pitch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1041
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1042 scaling_first=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1043 // if( pitch > 1.0 ) scaling_first=0; else scaling_first=1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1044
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1045 if ( !is_init || initialize || speed!=speed_act || pitch!=pitch_act ||
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1046 fade_shift != fade_shift_act ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1047
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1048 if( !is_init || initialize ) init_me=1; else init_me=0;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1049
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1050 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1051 fprintf(stderr,"snd_stretch_scale - init - pitch:%f, speed:%f\n",pitch,speed);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1052 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1053
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1054 speed_act = speed;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1055 pitch_act = pitch;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1056 if ( fade_shift != fade_shift_act ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1057 fprintf(stderr,"changed fade_shift_act\n");
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1058 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1059 fade_shift_act = fade_shift;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1060
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1061 // if (ring_buff!=0) free(ring_buff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1062 // if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1063
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1064 if (initialize != -1){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1065
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1066 dsnr = fade_shift;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1067 // dsnr = 1764; // 25Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1068 // dsnr = 1536; // 30Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1069 // dsnr = 1102; // 40Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1070 // dsnr = 882; // 50Hz
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1071
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1072 if( scaling_first ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1073 snr_stretching_i_max = ceil((double)snr_proc/pitch_act);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1074 snr_stretching_i_max += channels-1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1075 snr_stretching_i_max /= channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1076 snr_stretching_i_max *= channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1077 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1078 snr_stretching_i_max = (snr_proc+channels-1)/channels*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1079 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1080
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1081 snr_stretching_o_max =
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1082 ceil((double)snr_stretching_i_max / speed_eff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1083 snr_stretching_o_max =
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1084 (snr_stretching_o_max+channels-1)/channels*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1085
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1086 ring_size = snr_stretching_o_max /* for reading */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1087 + dsnr*channels /* for grabbing back */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1088 + dsnr*channels /* for readpos catching */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1089 /* up with writepos */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1090 + 2*dsnr*channels ; /* for 2 pre - echos */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1091 // ring_size = snr_stretching_o_max+3*dsnr*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1092
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1093 if( ring_size <= ring_size_old ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1094 ring_size = ring_size_old;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1095 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1096 fprintf(stderr," ring_size = %d \n",ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1097 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1098 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1099 /* if (ring_buff!=0) free(ring_buff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1100 if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1101 ring_buff = calloc( ring_size, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1102 buff_help = calloc( 65536, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1103 ring_pos_r = 0;*/
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1104 if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1105 ring_buff_old = ring_buff;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1106 ring_buff = calloc( ring_size, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1107 buff_help = calloc( 65536, sizeof(s16) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1108 if (ring_buff_old!=0) ringcopy( ring_buff, ring_size, ring_pos_r, ring_pos_w, ring_buff_old, ring_size_old, ring_pos_r );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1109 if (ring_buff_old!=0) free(ring_buff_old);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1110 // ring_pos_w=ringpos(ring_pos_w+ring_size_old,ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1111 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1112 fprintf(stderr," %d s16-samples reserved\n",ring_size);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1113 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1114 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1115
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1116 ring_pos_w =
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1117 ringpos( ring_pos_r + /* base */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1118 dsnr*channels /* for grabing back */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1119 // dsnr*2 /* for grabing back */ // why *2
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1120 , ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1121 #ifdef DEBUG
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1122 fprintf(stderr," ring_pos_w = %d\n",ring_pos_w);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1123 #endif
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1124 ring_pos_w = (ring_pos_w+(channels-1))/channels*channels;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1125
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1126 ring_size_old = ring_size;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1127
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1128 is_init = 1;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1129
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1130 } else { /* initialize == -1 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1131 if (ring_buff!=0) free(ring_buff);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1132 if (buff_help!=0) free(buff_help);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1133 /* buffers are released -> leave the function */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1134 return 0; /* !!! sloppy */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1135 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1136
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1137 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1138
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1139 if ( fabs(speed_eff-1.0)>0.001 ){ /*
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1140 0.001 ?!
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1141 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1142 this should be examined to the limits
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1143 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1144 */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1145 snr_stretch_i = (double)dsnr/(1.0/speed_eff-1.0);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1146 snr_stretch_o = fabs(snr_stretch_i + dsnr);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1147 snr_stretch_i = abs(snr_stretch_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1148 // fprintf(stderr,"snd_stretch_scale - snr_str_i=%d\n",snr_stretch_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1149 // fprintf(stderr,"snd_stretch_scale - snr_str_o=%d\n",snr_stretch_o);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1150 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1151 snr_stretch_i = 10;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1152 snr_stretch_o = 10;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1153 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1154
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1155 if ( pitch_eff!=1.0 ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1156 snr_scale_i = (double)dsnr/(1.0/pitch_eff-1.0);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1157 snr_scale_o = fabs(snr_scale_i + dsnr);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1158 snr_scale_i = abs(snr_scale_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1159 if( 1 /* optimized version doesnt support all scaling */ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1160 if( snr_scale_o > 65536 ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1161 snr_scale_i = (int)((double)snr_scale_i*((double)65536/(double)snr_scale_o)+0.5);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1162 snr_scale_o = 65536;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1163 // make sure that snr_o for sndscale wont exceed 2^16
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1164 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1165 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1166 // fprintf(stderr,"snd_stretch_scale - snr_sc_i=%d\n",snr_stretch_i);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1167 // fprintf(stderr,"snd_stretch_scale - snr_sc_o=%d\n",snr_stretch_o);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1168 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1169 // fprintf(stderr,"snd_stretch_scale - snr_scale_i=snr_scale_o=10\n");
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1170 snr_scale_i = 65536;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1171 snr_scale_o = 65536;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1172 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1173
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1174 if( 0/*scaling_first*/ ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1175
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1176 snr_proc_scale = snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1177 sndscale_job ( buff_i,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1178 snr_scale_i, snr_scale_o, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1179 buff_help, &snr_prod, snr_proc_scale, init_me,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1180 &(job->scale_job) );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1181 /* buff_o, &snr_prod, snr_proc_scale, 0 ); */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1182
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1183 if( speed_eff!=1.0 ){ /* add echo only when really stretching */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1184 if( !vol_corr ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1185 ringload_IIR_1_div_e_echo_i( ring_buff, ring_size, ring_pos_w, buff_help, snr_prod, dsnr*channels );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1186 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1187 ringload_IIR_1_div_e_echo_i_vc( ring_buff, ring_size, ring_pos_w, buff_help, snr_prod, dsnr*channels );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1188 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1189 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1190 ringload( ring_buff, ring_size, ring_pos_w, buff_help, snr_prod );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1191 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1192 ring_pos_w = ringpos( ring_pos_w+snr_prod, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1193
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1194 snr_proc_stretch = snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1195 sndstretch_job ( ring_buff, ring_size, ring_pos_r,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1196 snr_stretch_i*channels, snr_stretch_o*channels, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1197 buff_o, &snr_prod, snr_proc_stretch, init_me,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1198 &(job->stretch_job)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1199 );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1200
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1201 ring_pos_r = ringpos( ring_pos_r+snr_prod, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1202
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1203 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1204
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1205 // fprintf(stderr,"sndstretch: ring_pos_r = %d\n",ring_pos_r);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1206 // fprintf(stderr,"sndstretch: ring_pos_w = %d\n\n",ring_pos_w);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1207 snr_prod = snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1208 if( speed_eff!=1.0 ){ /* add echo only when really stretching */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1209 if( !vol_corr ){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1210 ringload_IIR_1_div_e_echo_i( ring_buff, ring_size, ring_pos_w, buff_i, snr_proc, dsnr*channels );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1211 }else{
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1212 ringload_IIR_1_div_e_echo_i_vc( ring_buff, ring_size, ring_pos_w, buff_i, snr_proc, dsnr*channels );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1213 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1214 } else {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1215 ringload( ring_buff, ring_size, ring_pos_w, buff_i, snr_proc );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1216 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1217 ring_pos_w = ringpos( ring_pos_w+snr_proc, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1218
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1219 snr_proc_stretch = snr_proc;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1220 sndstretch_job ( ring_buff, ring_size, ring_pos_r,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1221 snr_stretch_i*channels, snr_stretch_o*channels, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1222 buff_help, &snr_prod, snr_proc_stretch, init_me,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1223 &(job->stretch_job)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1224 );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1225
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1226 ring_pos_r = ringpos( ring_pos_r+snr_prod, ring_size );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1227
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1228 snr_proc_scale = snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1229 // fprintf(stderr,"snr_scale_i, snr_scale_o = %d,%d\n",snr_scale_i, snr_scale_o);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1230 sndscale_job ( buff_help,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1231 snr_scale_i, snr_scale_o, channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1232 buff_o, &snr_prod, snr_proc_scale, init_me,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1233 &(job->scale_job)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1234 );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1235
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1236 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1237
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1238 *snr_produced = snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1239
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1240 return snr_prod;
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1241 #undef ring_buff
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1242 #undef ring_buff_old
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1243 #undef buff_help
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1244 #undef ring_size
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1245 #undef ring_size_old
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1246 #undef ring_pos_w
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1247 #undef ring_pos_r
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1248 #undef snr_scale_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1249 #undef snr_scale_o
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1250 #undef snr_stretch_i
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1251 #undef snr_stretch_o
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1252 #undef snr_proc_scale
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1253 #undef snr_proc_stretch
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1254 #undef is_init
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1255 #undef dsnr
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1256 #undef speed_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1257 #undef pitch_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1258 #undef fade_shift_act
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1259 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1260
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1261
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1262 int snd_stretch_scale(s16 *buff_i, s16 * buff_o,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1263 double pitch, double speed, int channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1264 int snr_proc, int * snr_produced, int initialize
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1265 )
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1266 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1267 return snd_pitch_speed(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1268 /* input */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1269 buff_i, channels, snr_proc,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1270 /* algorihm parameters */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1271 initialize, pitch, speed, 1764,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1272 /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1273 buff_o, snr_produced
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1274 );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1275 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1276
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1277
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1278 int snd_stretch_scale_job(s16 *buff_i, s16 * buff_o,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1279 double pitch, double speed, int channels,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1280 int snr_proc, int * snr_produced, int initialize,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1281 PitchSpeedJob * job, int init_job)
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1282 /* init_job should be set to one the first time the routine is called with
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1283 the actual job (e.g. for creating a new job) */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1284 {
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1285 if(init_job){
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1286 InitPitchSpeedJob(job);
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1287 }
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1288 return snd_pitch_speed_job(
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1289 /* input */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1290 buff_i, channels, snr_proc,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1291 /* algorihm parameters */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1292 initialize, pitch, speed, 1764 ,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1293 /* output */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1294 buff_o, snr_produced,
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1295 /* job data */
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1296 job, 0
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1297 );
6bb0e52df3d6 [svn] - Made port of XMMS plugin SndStretch
mf0102
parents:
diff changeset
1298 }