Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / WTL

Multidevice ASIO output plugin for WinAMP

Rate me:
Please Sign up or sign in to vote.
4.80/5 (9 votes)
13 Feb 2009CDDL27 min read 48.1K   728   23  
A tiny WinAMP output DLL that uses a C++ replacement of the official ASIO SDK that supports multiple ASIO devices.
#pragma once

#include "buffers.hpp"
#include "WAOutModule.hpp"

#include "ASIO SDK/common/asio.h"


namespace WinAMP
{

namespace OutModule
{

////////////////////////////////////////////////////////////////////////////////
//
//  Writer
//  ------
//
//  Wraps a buffer dedicated for a single ASIO output sample type as well as
// additional data and functionality required for WinAMP interaction (mainly the
// the write callback used for transforming the input data into the output
// format).
//
////////////////////////////////////////////////////////////////////////////////

class Writer
{
public:
    MultiChannelBuffer               & buffer                   ()                                                    { return buffer_                                 ; }
    MultiChannelBuffer         const & buffer                   ()                                              const { return const_cast<Writer &>( *this ).buffer()  ; }
    WAOutModule::WriteCallback         callback                 ()                                              const { assert( writeCallback_ ); return writeCallback_; }
    size_t                             outputBytesPerSample     ()                                              const { return outputBytesPerSample_                   ; }
    ASIOSampleType                     outputSampleType         ()                                              const { return outputSampleType_                       ; }
    int                                write                    ( char * const buffer, int const bufferLength ) const { return callback()( buffer, bufferLength )      ; }
    int                                writtenTimeInMilliseconds()                                              const;

    bool setUpForIOParameters( int inputBitsPerSecond, size_t outputSampleRate );

    typedef int (Writer::*unspecified_bool_type)() const;
    operator unspecified_bool_type() const { return writeCallback_ ? &Writer::writtenTimeInMilliseconds : 0; }

private: // WriterForASIOSampleType private interface.
    template <ASIOSampleType> friend class WriterForASIOSampleType;
    Writer( ASIOSampleType, size_t outputBytesPerSample );

private: // Non copyable.
    Writer        ( Writer const & );
    void operator=( Writer const & );

private:
    MultiChannelBuffer               buffer_              ;
    WAOutModule::WriteCallback       writeCallback_       ;
    size_t                           outputSampleRate_    ;
    ASIOSampleType             const outputSampleType_    ;
    size_t                     const outputBytesPerSample_;
};


Writer       & getOutputSampleTypeWriter( ASIOSampleType                     );
Writer const & getReadersWriter         ( MultiChannelBuffer::Reader const & );


}   // namespace OutModule

}   // namespace WinAMP

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer Little Endian Ltd.
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions