changeset 9:cf38ffea8def

Added AODevice and AODriver. Renamed AOOptions.cpp file.
author Eris Caffee <discordia@eldalin.com>
date Wed, 25 Mar 2015 16:25:10 -0500
parents 65c716ba7cda
children d51a735106c2
files src/AODevice.cpp src/AODriver.cpp src/AOOption.cpp src/AOOptions.cpp src/aopp.hpp
diffstat 5 files changed, 129 insertions(+), 30 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/AODevice.cpp	Wed Mar 25 16:25:10 2015 -0500
     1.3 @@ -0,0 +1,13 @@
     1.4 +#include "aopp.hpp"
     1.5 +
     1.6 +AOPP::AODevice::AODevice( ao_device * dev ) :
     1.7 +    device (dev) {
     1.8 +    }
     1.9 +
    1.10 +int AOPP::AODevice::play( char *output_samples, uint32_t num_bytes ) {
    1.11 +    return ao_play( device, output_samples, num_bytes );
    1.12 +    }
    1.13 +
    1.14 +int AOPP::AODevice::close( void ) {
    1.15 +    return ao_close( device );
    1.16 +    }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/AODriver.cpp	Wed Mar 25 16:25:10 2015 -0500
     2.3 @@ -0,0 +1,52 @@
     2.4 +#include "aopp.hpp"
     2.5 +
     2.6 +using namespace AOPP;
     2.7 +
     2.8 +AODriver::AODriver( int id ) :
     2.9 +    driver_id (id) {
    2.10 +    }
    2.11 +
    2.12 +AOInfo * AODriver::driver_info( void ) {
    2.13 +    return ao_driver_info( driver_id );
    2.14 +    }
    2.15 +
    2.16 +#if 0
    2.17 +// ao_file_extension not in my libao ?
    2.18 +const char * AODriver::file_extension( void ) {
    2.19 +    return ao_file_extension( driver_id );
    2.20 +    }
    2.21 +#endif
    2.22 +
    2.23 +AODevice * AODriver::open_file( const char *filename, int overwrite, AOSampleFormat *format, AOOptions *options ) {
    2.24 +    ao_device * dev = ao_open_file(
    2.25 +        driver_id, 
    2.26 +        filename,
    2.27 +        overwrite,
    2.28 +        static_cast<ao_sample_format *> (format),
    2.29 +        options->options
    2.30 +        );
    2.31 +    if ( dev ) {
    2.32 +        AODevice *d;
    2.33 +        *d = AODevice( dev );
    2.34 +        return d;
    2.35 +        }
    2.36 +    return NULL;
    2.37 +    }
    2.38 +
    2.39 +AODevice * AODriver::open_live( AOSampleFormat *format, AOOptions *options ) {
    2.40 +    ao_device * dev = ao_open_live(
    2.41 +        driver_id,
    2.42 +        static_cast<ao_sample_format *> (format),
    2.43 +        options->options
    2.44 +        );
    2.45 +    if ( dev ) {
    2.46 +        AODevice *d;
    2.47 +        *d = AODevice( dev );
    2.48 +        return d;
    2.49 +        }
    2.50 +    return NULL;
    2.51 +    }
    2.52 +
    2.53 +int AODriver::get_driver_id( const char *short_name ) {
    2.54 +    return ao_driver_id( short_name );
    2.55 +    }
     3.1 --- a/src/AOOption.cpp	Wed Mar 25 12:21:35 2015 -0500
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,30 +0,0 @@
     3.4 -#include "aopp.hpp"
     3.5 -#include <cstdio>
     3.6 -
     3.7 -AOPP::AOOptions::AOOptions() :
     3.8 -    options (NULL)
     3.9 -    {
    3.10 -    }
    3.11 -
    3.12 -AOPP::AOOptions::~AOOptions() {
    3.13 -    if ( options ) {
    3.14 -        ao_free_options( options );
    3.15 -        }
    3.16 -    }
    3.17 -
    3.18 -
    3.19 -int AOPP::AOOptions::append( const char *key, const char *value ) {
    3.20 -    if ( key && value ) {
    3.21 -        return ao_append_option( &options, key, value );
    3.22 -        }
    3.23 -    return 0;
    3.24 -    }
    3.25 -
    3.26 -
    3.27 -void AOPP::AOOptions::print_options(void) {
    3.28 -    ao_option * opt = options;
    3.29 -    while ( opt ) {
    3.30 -        printf("%s\t\t%s\n", opt->key, opt->value);
    3.31 -        opt = opt->next;
    3.32 -        }
    3.33 -    }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/AOOptions.cpp	Wed Mar 25 16:25:10 2015 -0500
     4.3 @@ -0,0 +1,30 @@
     4.4 +#include "aopp.hpp"
     4.5 +#include <cstdio>
     4.6 +
     4.7 +AOPP::AOOptions::AOOptions() :
     4.8 +    options (NULL)
     4.9 +    {
    4.10 +    }
    4.11 +
    4.12 +AOPP::AOOptions::~AOOptions() {
    4.13 +    if ( options ) {
    4.14 +        ao_free_options( options );
    4.15 +        }
    4.16 +    }
    4.17 +
    4.18 +
    4.19 +int AOPP::AOOptions::append( const char *key, const char *value ) {
    4.20 +    if ( key && value ) {
    4.21 +        return ao_append_option( &options, key, value );
    4.22 +        }
    4.23 +    return 0;
    4.24 +    }
    4.25 +
    4.26 +
    4.27 +void AOPP::AOOptions::print_options(void) {
    4.28 +    ao_option * opt = options;
    4.29 +    while ( opt ) {
    4.30 +        printf("%s\t\t%s\n", opt->key, opt->value);
    4.31 +        opt = opt->next;
    4.32 +        }
    4.33 +    }
     5.1 --- a/src/aopp.hpp	Wed Mar 25 12:21:35 2015 -0500
     5.2 +++ b/src/aopp.hpp	Wed Mar 25 16:25:10 2015 -0500
     5.3 @@ -2,6 +2,7 @@
     5.4  #define __AOPP_H__
     5.5  
     5.6  #include "ao/ao.h"
     5.7 +#include <cstdint>
     5.8  
     5.9  namespace AOPP {
    5.10  
    5.11 @@ -10,6 +11,8 @@
    5.12  
    5.13      ////////////////////////////////////////////////////////////////////////////
    5.14      class AOOptions {
    5.15 +        friend class AODriver;
    5.16 +
    5.17      public:
    5.18          AOOptions();
    5.19          ~AOOptions();
    5.20 @@ -22,6 +25,37 @@
    5.21          };
    5.22      
    5.23  
    5.24 +    ////////////////////////////////////////////////////////////////////////////
    5.25 +    class AODevice {
    5.26 +    public:
    5.27 +        AODevice( ao_device * dev );
    5.28 +        int play( char *output_samples, uint32_t num_bytes );
    5.29 +        int close( void );
    5.30 +
    5.31 +    private:
    5.32 +        AODevice();
    5.33 +        ao_device *device;
    5.34 +        };
    5.35 +
    5.36 +    ////////////////////////////////////////////////////////////////////////////
    5.37 +    class AODriver {
    5.38 +    public:
    5.39 +        AODriver( int id );
    5.40 +        AODevice * open_live( AOSampleFormat *format, AOOptions *options );
    5.41 +        AODevice * open_file( const char *filename, int overwrite, AOSampleFormat *format, AOOptions *options );
    5.42 +        AOInfo * driver_info( void );
    5.43 +#if 0
    5.44 +// ao_file_extension not in my libao ?
    5.45 +        const char * file_extension( void );
    5.46 +#endif
    5.47 +
    5.48 +        static int get_driver_id( const char *short_name );
    5.49 +
    5.50 +    private:
    5.51 +        AODriver();
    5.52 +        int driver_id;
    5.53 +        };
    5.54 +
    5.55      }
    5.56  
    5.57  #endif