itpp::SND_Out_File Class Reference
Source Coding Module » Audio

A class to write SND-files (the .au format) More...

`#include <itpp/srccode/audiofile.h>`

## Public Member Functions

| SND_Out_File ()
| Default constructor - creates uninitialized stream.
| SND_Out_File (const char *fname, const Audio_Stream_Description &d)
| Constructor from file name fname and stream description d.
| ~SND_Out_File ()
| Stream destructor.
bool | open (const char *fname, const Audio_Stream_Description &d)
| Open the file fname with stream description d.
void | close ()
| Close the file.
Audio_Stream_Description | get_description () const
| Get stream description.
bool | seek_write (std::streamoff pos)
| Set current position to write to pos (samples).
std::streamoff | tell_write ()
| Get current position in samples.
std::streamoff | num_samples () const
| Get number of samples in stream.
bool | write_sample (const double &s, int ch=0)
| Write single sample s at current position to channel ch.
bool | write_channel (const vec &v, int ch=0)
| Write the vector v to channel ch starting at current position.
bool | write (const mat &m)
| Write audio channels from columns of the matrix m starting at current position.

## Detailed Description

A class to write SND-files (the .au format)

Output stream uses underlying binary stream to write audio data to the audio file in au format. Audio can be written sample-by sample, channel-wise or taken column-wise from the input matrix

Following example illustrates write operations with SND_Out_File:

#include <itpp/srccode/audiofile.h>
using namespace itpp;
int main() {
//create stream description to store 8kHz 16-bit PCM stereo audio data
d = Audio_Stream_Description(enc_linear16, 8000,2);
//create audio stream
SND_Out_File f_out("inptut.au",d);
//fill input with 10004 Hz test tone
mat in(100,2);
for(int i = 0; i < 100; ++i){
in(i,0) = sin(2*pi*i*1004/8000);
in(i,1) = cos(2*pi*i*1004/8000);
}
//write audio samples
f_out.write(in);
//zero sample 5 in channel 0
f_out.seek_write(5); f_out.write_sample(0,0);
//zero samples 5..7 in channel 1
vec z(3); z(0) = 0.0; z(1) = 0.0; z(2) = 0.0;
f_out.seek_write(5); f_out.write_channel(z,1);
return 0;
}
audiofile.h
Definitions of audio Audio classes and functions.
itpp::Array
General array class.
Definition array.h:105
itpp::Audio_Stream_Description
Description of audio stream.
Definition audiofile.h:67
itpp::SND_Out_File
A class to write SND-files (the .au format)
Definition audiofile.h:283
itpp::sin
vec sin(const vec &x)
Sine function.
Definition trig_hyp.h:54
itpp::cos
vec cos(const vec &x)
Cosine function.
Definition trig_hyp.h:58
itpp
itpp namespace
Definition itmex.h:37
itpp::pi
const double pi
Constant Pi.
Definition misc.h:103

Definition at line 282 of file audiofile.h.

## Member Function Documentation

## get_description()

Audio_Stream_Description itpp::SND_Out_File::get_description | ( |  | ) | const

inline

Get stream description.

Definition at line 296 of file audiofile.h.

## seek_write()

bool itpp::SND_Out_File::seek_write | ( | std::streamoff | pos | ) |

inline

Set current position to write to pos (samples).

Definition at line 298 of file audiofile.h.

## tell_write()

std::streamoff itpp::SND_Out_File::tell_write | ( |  | ) |

inline

Get current position in samples.

Definition at line 309 of file audiofile.h.

## num_samples()

std::streamoff itpp::SND_Out_File::num_samples | ( |  | ) | const

inline

Get number of samples in stream.

Definition at line 317 of file audiofile.h.

## write_sample()

bool itpp::SND_Out_File::write_sample | ( | const double & | s,
|  | int | ch = `0`
| ) |  |

inline

Write single sample s at current position to channel ch.

Definition at line 319 of file audiofile.h.

## write_channel()

bool itpp::SND_Out_File::write_channel | ( | const vec & | v,
|  | int | ch = `0`
| ) |  |

inline

Write the vector v to channel ch starting at current position.

Definition at line 332 of file audiofile.h.

Referenced by itpp::snd_write_channel().

## write()

bool itpp::SND_Out_File::write | ( | const mat & | m | ) |

inline

Write audio channels from columns of the matrix m starting at current position.

Definition at line 345 of file audiofile.h.

Referenced by itpp::snd_write().

The documentation for this class was generated from the following file:

- itpp/srccode/audiofile.h

Generated on Mon Jun 10 2024 11:49:40 for IT++ by Doxygen 1.9.8