itpp::SND_In_File Class Reference
Source Coding Module » Audio

Class to read audio data from au file. More...

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

## Public Member Functions

| SND_In_File ()
| Default constructor - creates uninitialized stream.
| SND_In_File (const char *fname)
| Constructor from file name fname.
| ~SND_In_File ()
| Stream destructor.
bool | open (const char *fname)
| Open the file fname.
void | close ()
| Close the file.
Audio_Stream_Description | get_description () const
| Get stream description.
bool | seek_read (std::streamoff pos)
| Go to sample number pos.
std::streamoff | tell_read ()
| Get current position in samples.
std::streamoff | num_samples () const
| Get number of samples in stream.
bool | read_sample (double &s, int ch=0)
| Read single sample s at current position to channel ch.
vec | read_channel (int n, int ch=0)
| Read n samples from channel ch starting at current position.
mat | read (int n)
| Read n samples from all channels starting at current position into matrix.

## Detailed Description

Class to read audio data from au file.

Input stream of audio samples uses binary stream to get encoded audio data from snd audio file. Audio can be read as single sample from current read position in audio stream, as a vector of samples containing data from single audio channel or as matrix with audio channels stored columnwise.

Following example illustratates read operations with SND_In_File

#include <itpp/srccode/audiofile.h>
using namespace itpp;
int main() {
//create audio stream
SND_In_File f_in("inptut.au");
//get description
Audio_Stream_Description d = f_in.get_description();
//read 100 audio samples if file contains stereo data on 8 kHz sampling rate
mat in(100,2); vec first_channel(100); vec second_channel(100);
if((d.get_num_channels == 2) && (d.get_sampling_rate() == 8000) && (f_in.num_samples()>=100))
{
in = f_in.read(100);
f_in.seek_read(0); //reposition to the first sample
first_channel = f_in.read_channel(100); //read first channel
f_in.seek_read(0); //reposition to the first sample
second_channel = f_in.read_channel(100,1); //read second channel
}
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::Audio_Stream_Description::get_num_channels
int get_num_channels() const
Get number of audio channels.
Definition audiofile.h:87
itpp::Audio_Stream_Description::get_sampling_rate
int get_sampling_rate() const
Get sampling rate (samples per second)
Definition audiofile.h:85
itpp::SND_In_File
Class to read audio data from au file.
Definition audiofile.h:177
itpp
itpp namespace
Definition itmex.h:37

Definition at line 176 of file audiofile.h.

## Member Function Documentation

## get_description()

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

inline

Get stream description.

Definition at line 190 of file audiofile.h.

## seek_read()

bool itpp::SND_In_File::seek_read | ( | std::streamoff | pos | ) |

inline

Go to sample number pos.

Definition at line 192 of file audiofile.h.

Referenced by itpp::snd_read(), and itpp::snd_read_channel().

## tell_read()

std::streamoff itpp::SND_In_File::tell_read | ( |  | ) |

inline

Get current position in samples.

Definition at line 203 of file audiofile.h.

## num_samples()

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

inline

Get number of samples in stream.

Definition at line 211 of file audiofile.h.

Referenced by itpp::snd_read(), and itpp::snd_read_channel().

## read_sample()

bool itpp::SND_In_File::read_sample | ( | double & | s,
|  | int | ch = `0`
| ) |  |

inline

Read single sample s at current position to channel ch.

Definition at line 213 of file audiofile.h.

## read_channel()

vec itpp::SND_In_File::read_channel | ( | int | n,
|  | int | ch = `0`
| ) |  |

inline

Read n samples from channel ch starting at current position.

Definition at line 221 of file audiofile.h.

Referenced by itpp::snd_read_channel(), and itpp::snd_read_channel().

## read()

mat itpp::SND_In_File::read | ( | int | n | ) |

inline

Read n samples from all channels starting at current position into matrix.

Definition at line 229 of file audiofile.h.

Referenced by itpp::snd_read(), and itpp::snd_read().

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