diff options
author | couriersud <couriersud@arcor.de> | 2015-08-04 13:53:29 +0200 |
---|---|---|
committer | couriersud <couriersud@arcor.de> | 2015-08-10 21:50:34 +0200 |
commit | d6b1cf85c55592f2c1a276b9fd42dfbd639511aa (patch) | |
tree | f766fd550c610fc92e109e45767595fc2fe688a8 /src/tools | |
parent | 210a006833141f76d76833c91677f368ea07e8c4 (diff) |
More usage of streams and aligned exception use. (nw)
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/nltool.c | 4 | ||||
-rw-r--r-- | src/tools/nlwav.c | 43 |
2 files changed, 22 insertions, 25 deletions
diff --git a/src/tools/nltool.c b/src/tools/nltool.c index 0153653ba25..a13d7dd183c 100644 --- a/src/tools/nltool.c +++ b/src/tools/nltool.c @@ -280,7 +280,7 @@ struct input_t double t; int e = line.scanf("%lf,%[^,],%lf", &t, buf, &m_value); if ( e!= 3) - throw netlist::fatalerror_e("error %d scanning line %s\n", e, line.cstr()); + throw netlist::fatalerror_e(pstring::sprintf("error %d scanning line %s\n", e, line.cstr())); m_time = netlist::netlist_time::from_double(t); m_param = netlist->setup().find_param(buf, true); } @@ -291,7 +291,7 @@ struct input_t { case netlist::param_t::MODEL: case netlist::param_t::STRING: - throw netlist::fatalerror_e("param %s is not numeric\n", m_param->name().cstr()); + throw netlist::fatalerror_e(pstring::sprintf("param %s is not numeric\n", m_param->name().cstr())); case netlist::param_t::DOUBLE: static_cast<netlist::param_double_t*>(m_param)->setTo(m_value); break; diff --git a/src/tools/nlwav.c b/src/tools/nlwav.c index d2bc2268a3e..862888b2eed 100644 --- a/src/tools/nlwav.c +++ b/src/tools/nlwav.c @@ -47,15 +47,13 @@ public: class wav_t { public: - wav_t(const pstring &fn, unsigned sr) + wav_t(postream &strm, unsigned sr) : m_f(strm) { - m_f = std::fopen(fn.cstr(),"w"); - if (m_f==NULL) - throw netlist::fatalerror_e("Error opening output file: %s", fn.cstr()); +// m_f = strm; initialize(sr); - std::fwrite(&m_fh, sizeof(m_fh), 1, m_f); - std::fwrite(&m_fmt, sizeof(m_fmt), 1, m_f); - std::fwrite(&m_data, sizeof(m_data), 1, m_f); + m_f.write(&m_fh, sizeof(m_fh)); + m_f.write(&m_fmt, sizeof(m_fmt)); + m_f.write(&m_data, sizeof(m_data)); } ~wav_t() { @@ -69,24 +67,17 @@ public: { m_data.len += m_fmt.block_align; short ps = sample; /* 16 bit sample, FIXME: powerpc? */ - std::fwrite(&ps, sizeof(ps), 1, m_f); + m_f.write(&ps, sizeof(ps)); } void close() { - if (m_f != NULL) - { - std::fseek(m_f, 0, SEEK_SET); - std::fwrite(&m_fh, sizeof(m_fh), 1, m_f); - std::fwrite(&m_fmt, sizeof(m_fmt), 1, m_f); - - //data.len = fmt.block_align * n; - std::fwrite(&m_data, sizeof(m_data), 1, m_f); - + m_f.seek(0); + m_f.write(&m_fh, sizeof(m_fh)); + m_f.write(&m_fmt, sizeof(m_fmt)); - std::fclose(m_f); - m_f = NULL; - } + //data.len = fmt.block_align * n; + m_f.write(&m_data, sizeof(m_data)); } private: struct riff_chunk_t @@ -139,17 +130,22 @@ private: riff_format_t m_fmt; riff_data_t m_data; - FILE *m_f; + postream &m_f; }; void convert(nlwav_options_t &opts) { - wav_t wo(opts.opt_out(), 48000); + pofilestream fo(opts.opt_out()); + if (fo.bad()) + { + throw netlist::fatalerror_e("Error opening output file: " + opts.opt_out()); + } + wav_t wo(fo, 48000); pifilestream fin(opts.opt_inp()); if (fin.bad()) - throw netlist::fatalerror_e("Error opening input file: %s", opts.opt_inp().cstr()); + throw netlist::fatalerror_e("Error opening input file: " + opts.opt_inp()); double dt = 1.0 / (double) wo.sample_rate(); double ct = dt; @@ -222,6 +218,7 @@ void convert(nlwav_options_t &opts) printf("Amp + %f\n", 32000.0 / (maxsam- mean)); printf("Amp - %f\n", -32000.0 / (minsam- mean)); wo.close(); + fo.close(); fin.close(); } |