~ubuntu-branches/ubuntu/natty/ultrastar-ng/natty

« back to all changes in this revision

Viewing changes to audio/audio_dev_pa.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Miriam Ruiz, Miriam Ruiz, Mario Bonino, Jon Dowland, Ansgar Burchardt
  • Date: 2008-06-07 16:43:18 UTC
  • mfrom: (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080607164318-4cnzizck1tp8mrwp
Tags: 0.2.1-1
[ Miriam Ruiz ]
* New Upstream Release (Closes: #453132)
* Removed unneeded patches
* Added packages to build deps:
  + libtool
  + portaudio19-dev | portaudio-dev
  + libboost-dev, libboost-thread-dev, libboost-serialization-dev
  + libboost-program-options-dev, libboost-regex-dev
* Moved shared objects to private directory: /usr/lib/ultraster-ng
* Added rpath to binaries to search for shared objects in the private dir
* Uses ultrastar-ng-gstreamer as default, instead of ultrastar-ng-xine,
  since there are significantly less issues with GStreamer.
* Added patch to fix upstream desktop file
* Added -Wl,-as-needed to LDFLAGS
* Replaced fftw3-dev by libfftw3-dev in build dependencies.
* Standards-Version upgraded to 3.7.3

[ Mario Bonino ]
* Fixed data/Makefile.am to install .desktop file and icon

[ Jon Dowland ]
* add Homepage: control field to source stanza
* fix a bashism in debian/rules (Closes: #478634)

[ Ansgar Burchardt ]
* debian/control: Change XS-Vcs-* to Vcs-*
* Remove Homepage semi-field from description

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "audio_dev.hpp"
 
2
#include <portaudio.h>
 
3
#include <ostream>
 
4
#include <sstream>
 
5
 
 
6
namespace {
 
7
        using namespace da;
 
8
        class pa19_record: public record::dev {
 
9
                static int c_callback(const void* input, void*, unsigned long frames, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void* userdata)
 
10
                {
 
11
                        pa19_record& self = *static_cast<pa19_record*>(userdata);
 
12
                        int16_t const* iptr = static_cast<int16_t const*>(input);
 
13
                        try {
 
14
                                std::vector<sample_t> buf(frames * self.s.channels());
 
15
                                std::transform(iptr, iptr + buf.size(), buf.begin(), conv_from_s16);
 
16
                                pcm_data data(&buf[0], frames, self.s.channels());
 
17
                                self.s.callback()(data, self.s);
 
18
                        } catch (std::exception& e) {
 
19
                                self.s.debug(std::string("Exception from recording callback: ") + e.what());
 
20
                        }
 
21
                        return paContinue;
 
22
                }
 
23
                settings s;
 
24
                struct init {
 
25
                        init() {
 
26
                                PaError err = Pa_Initialize();
 
27
                                if( err != paNoError ) throw std::runtime_error(std::string("Cannot initialize PortAudio: ") + Pa_GetErrorText(err));
 
28
                        }
 
29
                        ~init() { Pa_Terminate(); }
 
30
                } initialize;
 
31
                struct strm {
 
32
                        PaStream* handle;
 
33
                        strm( pa19_record* rec) {
 
34
                                PaStreamParameters p;
 
35
                                if (rec->s.subdev().empty()) {
 
36
                                        p.device = Pa_GetDefaultInputDevice();
 
37
                                } else {
 
38
                                        std::istringstream iss(rec->s.subdev());
 
39
                                        iss >> p.device;
 
40
                                        if (!iss.eof() || p.device < 0 || p.device > Pa_GetDeviceCount() - 1) throw std::invalid_argument("Invalid PortAudio device number");
 
41
                                }
 
42
                                p.channelCount = rec->s.channels();
 
43
                                p.sampleFormat = paInt16;
 
44
                                if (rec->s.frames() != settings::high) p.suggestedLatency = Pa_GetDeviceInfo(p.device)->defaultLowInputLatency;
 
45
                                else p.suggestedLatency = Pa_GetDeviceInfo(p.device)->defaultHighInputLatency;
 
46
                                p.hostApiSpecificStreamInfo = NULL;
 
47
                                PaError err = Pa_OpenStream(&handle, &p, NULL, rec->s.rate(), 50, paClipOff, rec->c_callback, rec);
 
48
                                if (err != paNoError) throw std::runtime_error("Cannot open PortAudio audio stream " + rec->s.subdev() + ": " + Pa_GetErrorText(err));
 
49
                        }
 
50
                        ~strm() { Pa_CloseStream(handle); }
 
51
                } stream;
 
52
          public:
 
53
                pa19_record(settings& s_orig): s(s_orig), initialize(), stream(this) {
 
54
                        PaError err = Pa_StartStream(stream.handle);
 
55
                        if( err != paNoError ) throw std::runtime_error("Cannot start PortAudio audio stream " + s.subdev() + ": " + Pa_GetErrorText(err));
 
56
                        s_orig = s;
 
57
                }
 
58
        };
 
59
        boost::plugin::simple<record_plugin, pa19_record> r(devinfo("pa", "PortAudio v19 PCM capture. Device number as settings (otherwise PA default)."));
 
60
}
 
61