summaryrefslogtreecommitdiffstats
path: root/noatun/library/conversion.cpp
blob: dbbf5b09744442b0ffea161bfbe8c898da271825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "noatun/conversion.h"

// inherit the aRts routines
#include <convert.h>

#include <config.h>
#include <limits.h>

namespace Conversion
{

void convertMono8ToFloat(unsigned long samples, unsigned char *from, float *to)
{
	Arts::convert_mono_8_float(samples, from, to);
}

void interpolateMono8ToFloat(unsigned long samples, double start, double speed,
                             unsigned char *from, float *to)
{
	Arts::interpolate_mono_8_float(samples, start, speed, from, to);
}

void convertMono16leToFloat(unsigned long samples, unsigned char *from, float *to)
{
	Arts::convert_mono_16le_float(samples, from, to);
}

void interpolateMono16leToFloat(unsigned long samples, double startpos, double speed,
                                unsigned char *from, float *to)
{
	Arts::interpolate_mono_16le_float(samples, startpos, speed, from, to);
}

void convertStereoI8To2Float(unsigned long samples, unsigned char *from,
                             float *left, float *right)
{
	Arts::convert_stereo_i8_2float(samples, from, left, right);
}


void interpolateStereoI8To2Float(unsigned long samples, double startpos, double speed,
                                 unsigned char *from, float *left, float *right)
{
	Arts::interpolate_stereo_i8_2float(samples, startpos, speed, from, left, right);
}

void convertStereoI16leTo2Float(unsigned long samples, unsigned char *from, float *left,
                                float *right)
{
	Arts::convert_stereo_i16le_2float(samples, from, left, right);
}

void interpolateStereoI16leTo2Float(unsigned long samples, double startpos, double speed,
                                    unsigned char *from, float *left, float *right)
{
	Arts::interpolate_stereo_i16le_2float(samples, startpos, speed, from, left, right);
}

void interpolateMonoFloatToFloat(unsigned long samples, double startpos, double speed,
                                 float *from, float *to)
{
	Arts::interpolate_mono_float_float( samples, startpos, speed,	from, to);
}

void convertStereoIFloatTo2Float(unsigned long samples,	float *from, float *left,
                                 float *right)
{
	Arts::convert_stereo_ifloat_2float(samples, from, left, right);
}

void interpolateStereoIFloatTo2Float(unsigned long samples, double startpos,
                                     double speed, float *from, float *left,
                                     float *right)
{
	Arts::interpolate_stereo_ifloat_2float(samples, startpos, speed, from, left, right);
}

void convertMonoFloatTo16le(unsigned long samples, float *from, unsigned char *to)
{
	Arts::convert_mono_float_16le(samples, from, to);
}

void convertStereo2FloatToI16le(unsigned long samples, float *left, float *right,
                                unsigned char *to)
{
	Arts::convert_stereo_2float_i16le(samples, left, right, to);
}

void convertMonoFloatTo8(unsigned long samples, float *from, unsigned char *to)
{
	Arts::convert_mono_float_8(samples, from, to);
}

void convertStereo2FloatToI8(unsigned long samples,	float *left, float *right,
                             unsigned char *to)
{
	Arts::convert_stereo_2float_i8(samples, left, right, to);
}

inline void toLittleEndian(unsigned long length, char *buffer)
{
#ifdef WORDS_BIGENDIAN
	swapEndian(length, buffer);
#else
	(void)length;
	(void)buffer;
#endif
}

inline void toBigEndian(unsigned long length, char *buffer)
{
#ifndef WORDS_BIGENDIAN
	swapEndian(length, buffer);
#else
	(void)length;
	(void)buffer;
#endif
}

void swapEndian(unsigned long length, char *buffer)
{
	// if you use a little-endian non intel box, and  the ASM
	// version doesn't work, it's safe to use the C version
#ifdef __i386__
	__asm__(
		"shrl $1,%0\n"
		"jz .l2\n"
		".l1:\n"
		"rolw $8,(%1)\n"
		"incl %1\n"
		"incl %1\n"
		"decl %0\n"
		"jnz .l1\n"
		".l2:\n"
		: : "r" (length), "r" (buffer));
#else
	while (length--)
	{
		char c=*(buffer+1);
		*(buffer+1)=*buffer;
		*(buffer)=c;
		buffer++; buffer++;
		--length;
	}
#endif
}

}