mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-11 00:40:00 +00:00
Some more work on square and the alsa output driver
This commit is contained in:
parent
ca4e7068d1
commit
15ea2a4be7
@ -33,7 +33,7 @@ else(WIN32 AND NOT UNIX)
|
||||
)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Modules )
|
||||
include(UseDoxygen)
|
||||
#include(UseDoxygen)
|
||||
set(DOXYFILE_OUTPUT_DIRECTORY docs)
|
||||
endif(WIN32 AND NOT UNIX)
|
||||
|
||||
|
@ -40,6 +40,101 @@ AlsaOut::AlsaOut()
|
||||
,device("default")
|
||||
,output(NULL)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "AlsaOut::AlsaOut() called" << std::endl;
|
||||
#endif
|
||||
int err;
|
||||
if ((err = snd_pcm_open (&waveHandle, 0, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot open audio device 0" << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: audio device opened" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot allocate hardware parameter structure " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: audio interface prepared for use" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = snd_pcm_hw_params_any (waveHandle, hw_params)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot initialize hardware parameter structure " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: audio interface prepared for use" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = snd_pcm_hw_params_set_access (waveHandle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot set access type " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: access type set" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = snd_pcm_hw_params_set_format (waveHandle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot set sample format " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: sample format set" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = snd_pcm_hw_params_set_rate_resample (waveHandle, hw_params, 44100)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot set sample rate " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: sample rate set" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = snd_pcm_hw_params_set_channels (waveHandle, hw_params, 2)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot set channel count " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: channel count set" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = snd_pcm_hw_params (waveHandle, hw_params)) < 0) {
|
||||
std::cerr << "AlsaOut: cannot set parameters " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: parameters set" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
snd_pcm_hw_params_free (hw_params);
|
||||
|
||||
if ((err = snd_pcm_prepare (waveHandle)) < 0) {
|
||||
std::cerr << "cannot prepare audio interface for use " << snd_strerror(err) << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else {
|
||||
std::cerr << "AlsaOut: audio interface prepared for use" << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
AlsaOut::~AlsaOut(){
|
||||
@ -52,6 +147,9 @@ AlsaOut::~AlsaOut(){
|
||||
|
||||
}
|
||||
|
||||
snd_pcm_t* AlsaOut::getWaveHandle() {
|
||||
return this->waveHandle;
|
||||
}
|
||||
|
||||
void AlsaOut::Destroy(){
|
||||
delete this;
|
||||
|
@ -62,6 +62,8 @@ class AlsaOut : public IOutput{
|
||||
virtual bool PlayBuffer(IBuffer *buffer,IPlayer *player);
|
||||
virtual void ReleaseBuffers();
|
||||
|
||||
snd_pcm_t* getWaveHandle();
|
||||
|
||||
public:
|
||||
typedef boost::shared_ptr<AlsaOutBuffer> AlsaOutBufferPtr;
|
||||
|
||||
@ -82,6 +84,7 @@ class AlsaOut : public IOutput{
|
||||
snd_pcm_t *waveHandle;
|
||||
snd_pcm_format_t waveFormat;
|
||||
snd_pcm_access_t waveAccess;
|
||||
snd_pcm_hw_params_t *hw_params;
|
||||
|
||||
// Current format
|
||||
int currentChannels;
|
||||
|
@ -78,9 +78,10 @@ bool AlsaOutBuffer::AddToOutput(){
|
||||
return true;
|
||||
}*/
|
||||
int err;
|
||||
frames = snd_pcm_writei(waveOut->waveHandle, (void*)data, bufferLength);
|
||||
snd_pcm_t* wHandle = waveOut->getWaveHandle();
|
||||
frames = snd_pcm_writei(wHandle, (void*)data, bufferLength);
|
||||
if (frames < 0)
|
||||
frames = snd_pcm_recover(waveOut->waveHandle, frames, 0);
|
||||
frames = snd_pcm_recover(wHandle, frames, 0);
|
||||
if (frames < 0) {
|
||||
printf("snd_pcm_writei failed: %s\n", snd_strerror(err));
|
||||
return false;
|
||||
|
@ -44,7 +44,7 @@ class AlsaOutPlugin : public musik::core::IPlugin
|
||||
void Destroy() { delete this; };
|
||||
|
||||
const utfchar* Name() { return TEXT("AlsaOut output plugin"); };
|
||||
const utfchar* Version() { return TEXT("1"); };
|
||||
const utfchar* Version() { return TEXT("0.1"); };
|
||||
const utfchar* Author() { return TEXT("Julian Cromarty"); };
|
||||
};
|
||||
|
||||
|
@ -38,5 +38,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <core/config.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
@ -46,6 +46,9 @@ PluginFactory PluginFactory::sInstance;
|
||||
|
||||
PluginFactory::PluginFactory(void){
|
||||
this->LoadPlugins();
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Loading DLLs" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
PluginFactory::~PluginFactory(void){
|
||||
|
@ -143,7 +143,9 @@ int Player::State(){
|
||||
}
|
||||
|
||||
void Player::ThreadLoop(){
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Player::ThreadLoop started" << std::endl;
|
||||
#endif
|
||||
// First start the stream
|
||||
this->stream = Stream::Create();
|
||||
if(this->stream->OpenStream(this->url)){
|
||||
|
@ -35,6 +35,7 @@
|
||||
#else
|
||||
#include <core/pch.hpp>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
#include <core/audio/Transport.h>
|
||||
|
||||
@ -64,26 +65,44 @@ void Transport::PrepareNextTrack(utfstring trackUrl){
|
||||
}
|
||||
|
||||
void Transport::Start(utfstring url){
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Transport::Start called" << std::endl;
|
||||
#endif
|
||||
// Check if this is already Prepared
|
||||
PlayerPtr player = this->nextPlayer;
|
||||
this->nextPlayer.reset();
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Transport: nextPlayer reset" << std::endl;
|
||||
#endif
|
||||
|
||||
// If the nextPlayer wasn't the same as the one started, lets create a new one
|
||||
if(!player || player->url!=url){
|
||||
// Or create a new player
|
||||
player = Player::Create(url);
|
||||
Player::OutputPtr output;
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Transport: new output created for player" << std::endl;
|
||||
#endif
|
||||
player = Player::Create(url, output);
|
||||
player->SetVolume(this->volume);
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Transport: new player created" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Add to the players
|
||||
this->players.push_front(player);
|
||||
this->currentPlayer = player;
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Transport: player added to player list" << std::endl;
|
||||
#endif
|
||||
|
||||
// Lets connect to the signals of the currentPlayer
|
||||
this->currentPlayer->PlaybackStarted.connect(this,&Transport::OnPlaybackStarted);
|
||||
this->currentPlayer->PlaybackAlmostEnded.connect(this,&Transport::OnPlaybackAlmostEnded);
|
||||
this->currentPlayer->PlaybackEnded.connect(this,&Transport::OnPlaybackEnded);
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cerr << "Transport: player-Play() about to be called" << std::endl;
|
||||
#endif
|
||||
// Start playing
|
||||
player->Play();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@
|
||||
#define WINVER 0x0501
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <windows.h>
|
||||
#include <TCHAR.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#ifndef MUSIKCOREIMPORT
|
||||
//#define DLLEXPORT __declspec( dllexport )
|
||||
|
@ -38,8 +38,11 @@
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifdef __MSVC__
|
||||
#define DB_ASSERT(x) _ASSERT(x==0)
|
||||
// #define DB_ASSERT(x) x
|
||||
#else //__MSVC__
|
||||
#define DB_ASSERT(x) x
|
||||
#endif//__MSVC
|
||||
#else
|
||||
#define DB_ASSERT(x) x
|
||||
#endif
|
||||
|
@ -62,6 +62,8 @@ ConsoleUI::ConsoleUI()
|
||||
// this->transport.EventMixpointReached.connect(&audioEventHandler, &DummyAudioEventHandler::OnMixpointReached);
|
||||
|
||||
this->transport.PlaybackStarted.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedOk);
|
||||
this->transport.PlaybackAlmostDone.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackAlmostEnded);
|
||||
this->transport.PlaybackEnded.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedFail);
|
||||
}
|
||||
|
||||
ConsoleUI::~ConsoleUI()
|
||||
@ -106,11 +108,11 @@ void ConsoleUI::PrintCommands()
|
||||
|
||||
void ConsoleUI::ProcessCommand(utfstring commandString)
|
||||
{
|
||||
using namespace boost::algorithm;
|
||||
//using namespace boost::algorithm;
|
||||
|
||||
Args args;
|
||||
|
||||
split(args, commandString, is_any_of(" "));
|
||||
boost::algorithm::split(args, commandString, boost::is_any_of(" "));
|
||||
|
||||
utfstring command = args.size() > 0 ? args[0] : UTF("");
|
||||
args.erase(args.begin());
|
||||
@ -154,7 +156,11 @@ void ConsoleUI::PlayFile(Args args)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef WIN32
|
||||
filename = UTF("C:\\temp\\musik\\ding.mp3"); //TODO: remove. For quick testing only
|
||||
#else
|
||||
filename = UTF("/tmp/test.mp3"); //TODO: remove. For quick testing only
|
||||
#endif
|
||||
}
|
||||
|
||||
int repeat = 1;
|
||||
@ -174,7 +180,7 @@ void ConsoleUI::PlayFile(Args args)
|
||||
|
||||
for (int i = 0; i < repeat; ++i)
|
||||
{
|
||||
// transport.Start(filename.c_str()); //TODO: fix to use TrackPtr
|
||||
transport.Start(filename.c_str()); //TODO: fix to use TrackPtr
|
||||
if (delay)
|
||||
{
|
||||
sleep(delay);
|
||||
|
@ -56,6 +56,7 @@ private: ConsoleUI* cui; // TODO: should probably be interface
|
||||
private: void PrintEvent(utfstring s);
|
||||
|
||||
// Slots
|
||||
public: void OnPlaybackAlmostEnded() { this->PrintEvent(UTF("Playback almost done")); };
|
||||
public: void OnPlaybackStartedOk() { this->PrintEvent(UTF("Playback started OK")); };
|
||||
public: void OnPlaybackStartedFail() { this->PrintEvent(UTF("Playback started FAIL")); };
|
||||
public: void OnPlaybackStoppedOk() { this->PrintEvent(UTF("Playback stopped OK")); };
|
||||
|
Loading…
x
Reference in New Issue
Block a user