Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
a4063aeb
Commit
a4063aeb
authored
Mar 25, 2018
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add another test case for the format converter.
parent
a4ddf179
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
130 additions
and
0 deletions
+130
-0
tests/mal_test_0.c
tests/mal_test_0.c
+130
-0
No files found.
tests/mal_test_0.c
View file @
a4063aeb
...
@@ -1127,6 +1127,136 @@ int do_format_converter_tests()
...
@@ -1127,6 +1127,136 @@ int do_format_converter_tests()
config
.
formatOut
=
mal_format_f32
;
// Interleaved/Interleaved f32 to f32.
{
mal_sine_wave_init
(
amplitude
,
periodsPerSecond
,
sampleRate
,
&
sineWave
);
result
=
mal_format_converter_init
(
&
config
,
converter_test_interleaved_callback
,
&
sineWave
,
&
converter
);
if
(
result
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize converter.
\n
"
);
return
-
1
;
}
float
interleavedFrames
[
MAL_MAX_CHANNELS
*
1024
];
mal_uint64
framesRead
=
mal_format_converter_read_frames
(
&
converter
,
1024
,
interleavedFrames
);
if
(
framesRead
!=
1024
)
{
printf
(
"Failed to read interleaved data from converter.
\n
"
);
return
-
1
;
}
FILE
*
pFile
=
mal_fopen
(
"res/output/converter_f32_to_f32_interleaved_interleaved__stereo_48000.raw"
,
"wb"
);
if
(
pFile
==
NULL
)
{
printf
(
"Failed to open output file.
\n
"
);
return
-
1
;
}
fwrite
(
interleavedFrames
,
sizeof
(
float
),
framesRead
*
converter
.
config
.
channels
,
pFile
);
fclose
(
pFile
);
}
// Interleaved/Deinterleaved f32 to f32.
{
mal_sine_wave_init
(
amplitude
,
periodsPerSecond
,
sampleRate
,
&
sineWave
);
result
=
mal_format_converter_init
(
&
config
,
converter_test_interleaved_callback
,
&
sineWave
,
&
converter
);
if
(
result
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize converter.
\n
"
);
return
-
1
;
}
float
separatedFrames
[
MAL_MAX_CHANNELS
][
1024
];
void
*
ppSeparatedFrames
[
MAL_MAX_CHANNELS
];
for
(
mal_uint32
iChannel
=
0
;
iChannel
<
converter
.
config
.
channels
;
iChannel
+=
1
)
{
ppSeparatedFrames
[
iChannel
]
=
&
separatedFrames
[
iChannel
];
}
mal_uint64
framesRead
=
mal_format_converter_read_frames_separated
(
&
converter
,
1024
,
ppSeparatedFrames
);
if
(
framesRead
!=
1024
)
{
printf
(
"Failed to read interleaved data from converter.
\n
"
);
return
-
1
;
}
// Write a separate file for each channel.
for
(
mal_uint32
iChannel
=
0
;
iChannel
<
converter
.
config
.
channels
;
iChannel
+=
1
)
{
char
filePath
[
256
];
snprintf
(
filePath
,
sizeof
(
filePath
),
"res/output/converter_f32_to_f32_interleaved_deinterleaved__stereo_48000.raw.%d"
,
iChannel
);
FILE
*
pFile
=
mal_fopen
(
filePath
,
"wb"
);
if
(
pFile
==
NULL
)
{
printf
(
"Failed to open output file.
\n
"
);
return
-
1
;
}
fwrite
(
ppSeparatedFrames
[
iChannel
],
sizeof
(
float
),
framesRead
,
pFile
);
fclose
(
pFile
);
}
}
// Deinterleaved/Interleaved f32 to f32.
{
mal_sine_wave_init
(
amplitude
,
periodsPerSecond
,
sampleRate
,
&
sineWave
);
result
=
mal_format_converter_init_separated
(
&
config
,
converter_test_separated_callback
,
&
sineWave
,
&
converter
);
if
(
result
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize converter.
\n
"
);
return
-
1
;
}
float
interleavedFrames
[
MAL_MAX_CHANNELS
*
1024
];
mal_uint64
framesRead
=
mal_format_converter_read_frames
(
&
converter
,
1024
,
interleavedFrames
);
if
(
framesRead
!=
1024
)
{
printf
(
"Failed to read interleaved data from converter.
\n
"
);
return
-
1
;
}
FILE
*
pFile
=
mal_fopen
(
"res/output/converter_f32_to_f32_deinterleaved_interleaved__stereo_48000.raw"
,
"wb"
);
if
(
pFile
==
NULL
)
{
printf
(
"Failed to open output file.
\n
"
);
return
-
1
;
}
fwrite
(
interleavedFrames
,
sizeof
(
float
),
framesRead
*
converter
.
config
.
channels
,
pFile
);
fclose
(
pFile
);
}
// Deinterleaved/Deinterleaved f32 to f32.
{
mal_sine_wave_init
(
amplitude
,
periodsPerSecond
,
sampleRate
,
&
sineWave
);
result
=
mal_format_converter_init_separated
(
&
config
,
converter_test_separated_callback
,
&
sineWave
,
&
converter
);
if
(
result
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize converter.
\n
"
);
return
-
1
;
}
float
separatedFrames
[
MAL_MAX_CHANNELS
][
1024
];
void
*
ppSeparatedFrames
[
MAL_MAX_CHANNELS
];
for
(
mal_uint32
iChannel
=
0
;
iChannel
<
converter
.
config
.
channels
;
iChannel
+=
1
)
{
ppSeparatedFrames
[
iChannel
]
=
&
separatedFrames
[
iChannel
];
}
mal_uint64
framesRead
=
mal_format_converter_read_frames_separated
(
&
converter
,
1024
,
ppSeparatedFrames
);
if
(
framesRead
!=
1024
)
{
printf
(
"Failed to read interleaved data from converter.
\n
"
);
return
-
1
;
}
// Write a separate file for each channel.
for
(
mal_uint32
iChannel
=
0
;
iChannel
<
converter
.
config
.
channels
;
iChannel
+=
1
)
{
char
filePath
[
256
];
snprintf
(
filePath
,
sizeof
(
filePath
),
"res/output/converter_f32_to_f32_deinterleaved_deinterleaved__stereo_48000.raw.%d"
,
iChannel
);
FILE
*
pFile
=
mal_fopen
(
filePath
,
"wb"
);
if
(
pFile
==
NULL
)
{
printf
(
"Failed to open output file.
\n
"
);
return
-
1
;
}
fwrite
(
ppSeparatedFrames
[
iChannel
],
sizeof
(
float
),
framesRead
,
pFile
);
fclose
(
pFile
);
}
}
return
0
;
return
0
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment