eDSP  0.0.1
A cross-platform DSP library written in C++.
Public Types | Public Member Functions | List of all members
edsp::io::decoder< T, N > Class Template Reference

This class implements a decoder object to read data from supported audio files. More...

#include <decoder.hpp>

Public Types

using index_type = std::ptrdiff_t
 
using value_type = T
 

Public Member Functions

 decoder ()=default
 
 ~decoder ()=default
 
bool open (const edsp::string_view &file_path)
 Opens an audio file. More...
 
void close ()
 Closes the audio file. More...
 
bool is_open () const noexcept
 Checks if the there is an audio file opened. More...
 
index_type samples () const noexcept
 Returns the number of samples in the audio file. More...
 
index_type frames () const noexcept
 
index_type channels () const noexcept
 Returns the number of channels in the audio file. More...
 
double duration () const noexcept
 Returns the duration of the audio file in seconds. More...
 
double samplerate () const noexcept
 Returns the sampling rate of the audio file in Hz. More...
 
bool seekable () const noexcept
 Checks if the audio file is seekable. More...
 
index_type seek (index_type position) noexcept
 Updates the current frame position for a track in an audio file. More...
 
index_type current () const noexcept
 Returns the current frame position of the track in an audio file. More...
 
template<typename OutputIt >
index_type read (OutputIt d_first, OutputIt d_last)
 Attempts to read data from the audio file and stores the results in the range [first, last) More...
 

Detailed Description

template<typename T, std::size_t N = 1024>
class edsp::io::decoder< T, N >

This class implements a decoder object to read data from supported audio files.

Template Parameters
TValue Type
NSize of the internal buffer.

Member Typedef Documentation

◆ index_type

template<typename T , std::size_t N = 1024>
using edsp::io::decoder< T, N >::index_type = std::ptrdiff_t

◆ value_type

template<typename T , std::size_t N = 1024>
using edsp::io::decoder< T, N >::value_type = T

Constructor & Destructor Documentation

◆ decoder()

template<typename T , std::size_t N = 1024>
edsp::io::decoder< T, N >::decoder ( )
explicitdefault

◆ ~decoder()

template<typename T , std::size_t N = 1024>
edsp::io::decoder< T, N >::~decoder ( )
default

Member Function Documentation

◆ channels()

template<typename T , std::size_t N = 1024>
index_type edsp::io::decoder< T, N >::channels ( ) const
inlinenoexcept

Returns the number of channels in the audio file.

The number of channels is a positive integer which specifies the number of interleaved audio channels in the given audio track.

Returns
Number of channels in the audio file.

◆ close()

template<typename T , std::size_t N = 1024>
void edsp::io::decoder< T, N >::close ( )
inline

Closes the audio file.

◆ current()

template<typename T , std::size_t N = 1024>
index_type edsp::io::decoder< T, N >::current ( ) const
inlinenoexcept

Returns the current frame position of the track in an audio file.

Returns
On success, returns the frame position in the audio track. On failure, return the value -1

◆ duration()

template<typename T , std::size_t N = 1024>
double edsp::io::decoder< T, N >::duration ( ) const
inlinenoexcept

Returns the duration of the audio file in seconds.

Returns
Duration of the audio file in seconds.

◆ frames()

template<typename T , std::size_t N = 1024>
index_type edsp::io::decoder< T, N >::frames ( ) const
inlinenoexcept

◆ is_open()

template<typename T , std::size_t N = 1024>
bool edsp::io::decoder< T, N >::is_open ( ) const
inlinenoexcept

Checks if the there is an audio file opened.

Returns
true if an audio file has been opened.

◆ open()

template<typename T , std::size_t N = 1024>
bool edsp::io::decoder< T, N >::open ( const edsp::string_view &  file_path)
inline

Opens an audio file.

Parameters
file_pathPath to the file to be opened.
Returns
true if the file has been opened, false otherwise.

◆ read()

template<typename T , std::size_t N = 1024>
template<typename OutputIt >
index_type edsp::io::decoder< T, N >::read ( OutputIt  d_first,
OutputIt  d_last 
)
inline

Attempts to read data from the audio file and stores the results in the range [first, last)

The function will try to read up to N samples, where N is the size of the range [first, last).

Parameters
d_firstOutput iterator defining the beginning of the output range.
d_lastOutput iterator defining the ending of the output range.
Returns
Number of samples read with success.

◆ samplerate()

template<typename T , std::size_t N = 1024>
double edsp::io::decoder< T, N >::samplerate ( ) const
inlinenoexcept

Returns the sampling rate of the audio file in Hz.

Returns
Sampling rate of the audio file in Hz.

◆ samples()

template<typename T , std::size_t N = 1024>
index_type edsp::io::decoder< T, N >::samples ( ) const
inlinenoexcept

Returns the number of samples in the audio file.

Note
The number of samples is proportional to the number of channels and frames.
Returns
Number of samples in the audio file.

◆ seek()

template<typename T , std::size_t N = 1024>
index_type edsp::io::decoder< T, N >::seek ( index_type  position)
inlinenoexcept

Updates the current frame position for a track in an audio file.

Parameters
positionFrame position in the audio track.
Returns
On success, returns the frame position in the audio track. On failure, return the value -1

◆ seekable()

template<typename T , std::size_t N = 1024>
bool edsp::io::decoder< T, N >::seekable ( ) const
inlinenoexcept

Checks if the audio file is seekable.

Returns
true if the audio file is seekable, false otherwise.

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