AudioFormat: replace struct audio_format_string with class StringBuffer, return it

This commit is contained in:
Max Kellermann
2017-01-17 22:04:31 +01:00
parent 4f01387edf
commit 39114f91a7
10 changed files with 36 additions and 53 deletions

View File

@@ -21,6 +21,7 @@
#include "FakeDecoderAPI.hxx"
#include "decoder/DecoderAPI.hxx"
#include "input/InputStream.hxx"
#include "util/StringBuffer.hxx"
#include "Compiler.h"
#include <stdexcept>
@@ -33,13 +34,11 @@ FakeDecoder::Ready(const AudioFormat audio_format,
gcc_unused bool seekable,
SignedSongTime duration)
{
struct audio_format_string af_string;
assert(!initialized);
assert(audio_format.IsValid());
fprintf(stderr, "audio_format=%s duration=%f\n",
audio_format_to_string(audio_format, &af_string),
ToString(audio_format).c_str(),
duration.ToDoubleS());
initialized = true;

View File

@@ -21,6 +21,7 @@
#include "TestAudioFormat.hxx"
#include "AudioFormat.hxx"
#include "AudioParser.hxx"
#include "util/StringBuffer.hxx"
#include <cppunit/TestAssert.h>
@@ -51,8 +52,7 @@ struct assertion_traits<AudioFormat>
static std::string toString(AudioFormat x)
{
struct audio_format_string s;
return audio_format_to_string(x, &s);
return ToString(x).c_str();
}
};
}
@@ -80,10 +80,8 @@ static constexpr AudioFormatStringTest af_mask_tests[] = {
void
AudioFormatTest::TestToString()
{
struct audio_format_string s;
for (const auto &i : af_string_tests)
CPPUNIT_ASSERT_EQUAL(i.s, audio_format_to_string(i.af, &s));
CPPUNIT_ASSERT_EQUAL(i.s, ToString(i.af).c_str());
}
void

View File

@@ -28,6 +28,7 @@
#include "pcm/Volume.hxx"
#include "mixer/MixerControl.hxx"
#include "util/ConstBuffer.hxx"
#include "util/StringBuffer.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
@@ -62,7 +63,6 @@ load_filter(const char *name)
int main(int argc, char **argv)
try {
struct audio_format_string af_string;
char buffer[4096];
if (argc < 3 || argc > 4) {
@@ -97,7 +97,7 @@ try {
const AudioFormat out_audio_format = filter->GetOutAudioFormat();
fprintf(stderr, "audio_format=%s\n",
audio_format_to_string(out_audio_format, &af_string));
ToString(out_audio_format).c_str());
/* play */

View File

@@ -33,6 +33,7 @@
#include "ReplayGainConfig.hxx"
#include "pcm/PcmConvert.hxx"
#include "filter/FilterRegistry.hxx"
#include "util/StringBuffer.hxx"
#include "util/RuntimeError.hxx"
#include "util/ScopeExit.hxx"
#include "Log.hxx"
@@ -86,9 +87,8 @@ run_output(AudioOutput *ao, AudioFormat audio_format)
ao_plugin_open(ao, audio_format);
AtScopeExit(ao) { ao_plugin_close(ao); };
struct audio_format_string af_string;
fprintf(stderr, "audio_format=%s\n",
audio_format_to_string(audio_format, &af_string));
ToString(audio_format).c_str());
size_t frame_size = audio_format.GetFrameSize();