No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
To be PAQ'ed and points refunded
Please leave any comments here within the
next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
guanwz
Main Topics
Browse All Topics





by: NeutronPosted on 2002-08-23 at 07:58:10ID: 7238745
Hi florinsuciu, :-)
-----Brese nham.java- ------
] = sourceSample[sourceIndex];
-----Brese nham.java- ------
You can try using Bresenham variation like this one:
-------8<-------cut-here--
public class Bresenham
{
public static void main( String[] args )
{
int[] sourceSample = {1,2,3,4,5,6,7};
// int[] sourceSample = {1,1,2,2,3,4,4,5,6,6,7,8};
int sourceRate = 32000; // 48000
int targetRate = 48000; // 32000
int targetLength = (sourceSample.length * targetRate) / sourceRate;
int[] targetSample = new int[targetLength];
int measure = targetRate;
int sourceIndex = 0;
int targetIndex = 0;
while (targetIndex<targetLength)
{
if (measure>=sourceRate)
{
targetSample[targetIndex++
measure -= sourceRate;
}
else
{
sourceIndex++;
measure+= targetRate;
}
}
System.out.print( "[" );
for (int i=0; i<sourceSample.length; i++)
{
System.out.print( sourceSample[i]+"; " );
}
System.out.println( "]" );
System.out.print( "[" );
for (int i=0; i<targetSample.length; i++)
{
System.out.print( targetSample[i]+"; " );
}
System.out.println( "]" );
}
} /* Bresenham */
-------8<-------cut-here--
This should work both ways from lower SR to higher and vice versa.
Example (input 32000 output 48000) :
[1; 2; 3; 4; 5; 6; 7; ]
[1; 2; 2; 3; 4; 4; 5; 6; 6; 7; ]
Example 2 (input 48000 output 32000) :
[1; 1; 2; 2; 3; 4; 4; 5; 6; 6; 7; 8; ]
[1; 2; 3; 4; 5; 6; 7; 8; ]
What I have done there is 'stretch' the sample data.
I hope that this solves your problem. :-)
Greetings,
</ntr> :)