git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4204 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.7
| @@ -393,6 +393,65 @@ int JackAlsaDriver::Write() | |||
| return alsa_driver_write((alsa_driver_t *)fDriver, fEngineControl->fBufferSize); | |||
| } | |||
| void JackAlsaDriver::ReadInputAux() | |||
| { | |||
| int chn; | |||
| for (chn = 0; chn < fCaptureChannels; chn++) { | |||
| if (fGraphManager->GetConnectionsNum(fCapturePortList[chn]) > 0) { | |||
| buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[chn], orig_nframes); | |||
| alsa_driver_read_from_channel((alsa_driver_t *)fDriver, chn, buf + nread, contiguous); | |||
| } | |||
| } | |||
| } | |||
| void JackAlsaDriver::MonitorInputAux() | |||
| { | |||
| int chn; | |||
| for (chn = 0; chn < fCaptureChannels; chn++) { | |||
| JackPort* port = fGraphManager->GetPort(fCapturePortList[chn]); | |||
| if (port->MonitoringInput()) { | |||
| driver->input_monitor_mask |= (1 << chn); | |||
| } | |||
| } | |||
| } | |||
| void JackAlsaDriver::ClearOutputAux() | |||
| { | |||
| int chn; | |||
| for (chn = 0; i < fPlaybackChannels; chn++) { | |||
| jack_default_audio_sample_t* buf = | |||
| (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[chn], fEngineControl->fBufferSize); | |||
| memset (buf, 0, sizeof (jack_default_audio_sample_t) * fEngineControl->fBufferSize); | |||
| } | |||
| } | |||
| void JackAlsaDriver::SetTimetAux(jack_time_t time) | |||
| { | |||
| fBeginDateUst = time; | |||
| } | |||
| void JackAlsaDriver::WriteOutputAux() | |||
| { | |||
| int chn; | |||
| jack_default_audio_sample_t* buf; | |||
| snd_pcm_sframes_t nwritten; | |||
| snd_pcm_sframes_t contiguous; | |||
| snd_pcm_uframes_t offset; | |||
| for (chn = 0; chn < fPlaybackChannels; chn++) { | |||
| // Ouput ports | |||
| if (fGraphManager->GetConnectionsNum(fPlaybackPortList[chn]) > 0) { | |||
| buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[chn], orig_nframes); | |||
| alsa_driver_write_to_channel(driver, chn, buf + nwritten, contiguous); | |||
| // Monitor ports | |||
| if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[chn]) > 0) { | |||
| monbuf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[chn], orig_nframes); | |||
| memcpy(monbuf + nwritten, buf + nwritten, contiguous * sizeof(jack_default_audio_sample_t)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| void | |||
| JackAlsaDriver::jack_driver_init (jack_driver_t *driver) | |||
| { | |||
| @@ -875,6 +934,8 @@ SERVER_EXPORT const jack_driver_desc_t* driver_get_descriptor () | |||
| return desc; | |||
| } | |||
| static Jack::JackAlsaDriver* g_alsa_driver; | |||
| SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params) | |||
| { | |||
| jack_nframes_t srate = 48000; | |||
| @@ -1001,8 +1062,8 @@ SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLocke | |||
| playback = TRUE; | |||
| } | |||
| Jack::JackAlsaDriver* alsa_driver = new Jack::JackAlsaDriver("system", "alsa_pcm", engine, table); | |||
| Jack::JackDriverClientInterface* threaded_driver = new Jack::JackThreadedDriver(alsa_driver); | |||
| g_alsa_driver = new Jack::JackAlsaDriver("system", "alsa_pcm", engine, table); | |||
| Jack::JackDriverClientInterface* threaded_driver = new Jack::JackThreadedDriver(g_alsa_driver); | |||
| // Special open for ALSA driver... | |||
| if (alsa_driver->Open(frames_per_interrupt, user_nperiods, srate, hw_monitoring, hw_metering, capture, playback, dither, soft_mode, monitor, | |||
| user_capture_nchnls, user_playback_nchnls, shorts_first, capture_pcm_name, playback_pcm_name, | |||
| @@ -1014,6 +1075,29 @@ SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLocke | |||
| } | |||
| } | |||
| // Code to be used in alsa_driver.c | |||
| void ReadInput(); | |||
| { | |||
| g_alsa_driver->ReadInputAux(); | |||
| } | |||
| void MonitorInput() | |||
| { | |||
| g_alsa_driver->MonitorInputAux(); | |||
| } | |||
| void ClearOutput() | |||
| { | |||
| g_alsa_driver->ClearOutputAux(); | |||
| } | |||
| void WriteOutput() | |||
| { | |||
| g_alsa_driver->WriteOutputAux(); | |||
| } | |||
| void SetTimet(jack_time_t time) | |||
| { | |||
| g_alsa_driver->SetTimetAux(time); | |||
| } | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| @@ -93,6 +93,12 @@ class JackAlsaDriver : public JackAudioDriver | |||
| int SetBufferSize(jack_nframes_t buffer_size); | |||
| void ReadInputAux(); | |||
| void MonitorInputtAux(); | |||
| void ClearOutputtAux(); | |||
| void WriteOutputtAux(); | |||
| void SetTimetAux(jack_time_t time); | |||
| // JACK API emulation for the midi driver | |||
| int is_realtime() const; | |||
| int create_thread(pthread_t *thread, int prio, int rt, void *(*start_func)(void*), void *arg); | |||
| @@ -1108,13 +1108,16 @@ alsa_driver_stop (alsa_driver_t *driver) | |||
| } | |||
| */ | |||
| // New code | |||
| int i; | |||
| for (i = 0; i < fPlaybackChannels; i++) { | |||
| jack_default_audio_sample_t* buf = | |||
| (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[i], fEngineControl->fBufferSize); | |||
| memset (buf, 0, sizeof (jack_default_audio_sample_t) * fEngineControl->fBufferSize); | |||
| } | |||
| // Steph | |||
| /* | |||
| int chn; | |||
| for (chn = 0; i < fPlaybackChannels; chn++) { | |||
| jack_default_audio_sample_t* buf = | |||
| (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[chn], fEngineControl->fBufferSize); | |||
| memset (buf, 0, sizeof (jack_default_audio_sample_t) * fEngineControl->fBufferSize); | |||
| } | |||
| */ | |||
| ClearOutput() | |||
| if (driver->playback_handle) { | |||
| if ((err = snd_pcm_drop (driver->playback_handle)) < 0) { | |||
| @@ -1346,7 +1349,8 @@ alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float | |||
| poll_ret = jack_get_microseconds (); | |||
| // Steph | |||
| fBeginDateUst = poll_ret; | |||
| //fBeginDateUst = poll_ret; | |||
| SetTime(poll_ret); | |||
| if (extra_fd < 0) { | |||
| if (driver->poll_next && poll_ret > driver->poll_next) { | |||
| @@ -1573,7 +1577,7 @@ alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes) | |||
| snd_pcm_uframes_t offset; | |||
| jack_nframes_t orig_nframes; | |||
| jack_default_audio_sample_t* buf; | |||
| channel_t chn; | |||
| // channel_t chn; | |||
| // JSList *node; | |||
| // jack_port_t* port; | |||
| int err; | |||
| @@ -1626,13 +1630,16 @@ alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes) | |||
| buf + nread, contiguous); | |||
| } | |||
| */ | |||
| int i; | |||
| for (chn = 0; chn < fCaptureChannels; chn++) { | |||
| if (fGraphManager->GetConnectionsNum(fCapturePortList[chn]) > 0) { | |||
| buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[chn], orig_nframes); | |||
| alsa_driver_read_from_channel (driver, chn, buf + nread, contiguous); | |||
| } | |||
| } | |||
| /* | |||
| int chn; | |||
| for (chn = 0; chn < fCaptureChannels; chn++) { | |||
| if (fGraphManager->GetConnectionsNum(fCapturePortList[chn]) > 0) { | |||
| buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[chn], orig_nframes); | |||
| alsa_driver_read_from_channel (driver, chn, buf + nread, contiguous); | |||
| } | |||
| } | |||
| */ | |||
| ReadInput(); | |||
| if ((err = snd_pcm_mmap_commit (driver->capture_handle, | |||
| offset, contiguous)) < 0) { | |||
| @@ -1699,13 +1706,16 @@ alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes) | |||
| } | |||
| } | |||
| */ | |||
| /* | |||
| int chn; | |||
| for (chn = 0; chn < fCaptureChannels; chn++) { | |||
| port = fGraphManager->GetPort(fCapturePortList[chn]); | |||
| if (port->MonitoringInput()) { | |||
| driver->input_monitor_mask |= (1 << chn); | |||
| } | |||
| } | |||
| for (chn = 0; chn < fCaptureChannels; chn++) { | |||
| port = fGraphManager->GetPort(fCapturePortList[chn]); | |||
| if (port->MonitoringInput()) { | |||
| driver->input_monitor_mask |= (1 << chn); | |||
| } | |||
| } | |||
| */ | |||
| MonitorInput(); | |||
| if (driver->hw_monitoring) { | |||
| if ((driver->hw->input_monitor_mask | |||
| @@ -1755,20 +1765,24 @@ alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes) | |||
| } | |||
| */ | |||
| // Steph | |||
| // Steph | |||
| /* | |||
| int chn; | |||
| for (chn = 0; chn < fPlaybackChannels; chn++) { | |||
| // Ouput ports | |||
| if (fGraphManager->GetConnectionsNum(fPlaybackPortList[chn]) > 0) { | |||
| buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[chn], orig_nframes); | |||
| alsa_driver_write_to_channel (driver, chn, buf + nwritten, contiguous); | |||
| // Monitor ports | |||
| if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[chn]) > 0) { | |||
| monbuf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[chn], orig_nframes); | |||
| memcpy(monbuf + nwritten, buf + nwritten, contiguous * sizeof(jack_default_audio_sample_t)); | |||
| } | |||
| } | |||
| } | |||
| for (chn = 0; chn < fPlaybackChannels; chn++) { | |||
| // Ouput ports | |||
| if (fGraphManager->GetConnectionsNum(fPlaybackPortList[chn]) > 0) { | |||
| buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[chn], orig_nframes); | |||
| alsa_driver_write_to_channel (driver, chn, buf + nwritten, contiguous); | |||
| // Monitor ports | |||
| if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[chn]) > 0) { | |||
| monbuf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[chn], orig_nframes); | |||
| memcpy(monbuf + nwritten, buf + nwritten, contiguous * sizeof(jack_default_audio_sample_t)); | |||
| } | |||
| } | |||
| } | |||
| */ | |||
| WriteOutput(); | |||
| if (!bitset_empty (driver->channels_not_done)) { | |||
| alsa_driver_silence_untouched_channels (driver, | |||
| @@ -98,7 +98,7 @@ typedef struct _alsa_driver { | |||
| snd_pcm_sw_params_t *playback_sw_params; | |||
| snd_pcm_hw_params_t *capture_hw_params; | |||
| snd_pcm_sw_params_t *capture_sw_params; | |||
| jack_hardware_t *hw; | |||
| jack_hardware_t *hw; | |||
| ClockSyncStatus *clock_sync_data; | |||
| jack_client_t *client; | |||
| JSList *capture_ports; | |||
| @@ -143,17 +143,17 @@ typedef struct _alsa_driver { | |||
| } alsa_driver_t; | |||
| static inline void | |||
| static inline void | |||
| alsa_driver_mark_channel_done (alsa_driver_t *driver, channel_t chn) { | |||
| bitset_remove (driver->channels_not_done, chn); | |||
| driver->silent[chn] = 0; | |||
| } | |||
| static inline void | |||
| static inline void | |||
| alsa_driver_silence_on_channel (alsa_driver_t *driver, channel_t chn, | |||
| jack_nframes_t nframes) { | |||
| if (driver->playback_interleaved) { | |||
| memset_interleave | |||
| memset_interleave | |||
| (driver->playback_addr[chn], | |||
| 0, nframes * driver->playback_sample_bytes, | |||
| driver->interleave_unit, | |||
| @@ -165,11 +165,11 @@ alsa_driver_silence_on_channel (alsa_driver_t *driver, channel_t chn, | |||
| alsa_driver_mark_channel_done (driver,chn); | |||
| } | |||
| static inline void | |||
| static inline void | |||
| alsa_driver_silence_on_channel_no_mark (alsa_driver_t *driver, channel_t chn, | |||
| jack_nframes_t nframes) { | |||
| if (driver->playback_interleaved) { | |||
| memset_interleave | |||
| memset_interleave | |||
| (driver->playback_addr[chn], | |||
| 0, nframes * driver->playback_sample_bytes, | |||
| driver->interleave_unit, | |||
| @@ -180,27 +180,27 @@ alsa_driver_silence_on_channel_no_mark (alsa_driver_t *driver, channel_t chn, | |||
| } | |||
| } | |||
| static inline void | |||
| static inline void | |||
| alsa_driver_read_from_channel (alsa_driver_t *driver, | |||
| channel_t channel, | |||
| jack_default_audio_sample_t *buf, | |||
| jack_nframes_t nsamples) | |||
| { | |||
| driver->read_via_copy (buf, | |||
| driver->read_via_copy (buf, | |||
| driver->capture_addr[channel], | |||
| nsamples, | |||
| nsamples, | |||
| driver->capture_interleave_skip[channel]); | |||
| } | |||
| static inline void | |||
| static inline void | |||
| alsa_driver_write_to_channel (alsa_driver_t *driver, | |||
| channel_t channel, | |||
| jack_default_audio_sample_t *buf, | |||
| channel_t channel, | |||
| jack_default_audio_sample_t *buf, | |||
| jack_nframes_t nsamples) | |||
| { | |||
| driver->write_via_copy (driver->playback_addr[channel], | |||
| buf, | |||
| nsamples, | |||
| buf, | |||
| nsamples, | |||
| driver->playback_interleave_skip[channel], | |||
| driver->dither_state+channel); | |||
| alsa_driver_mark_channel_done (driver, channel); | |||
| @@ -264,4 +264,12 @@ alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes); | |||
| int | |||
| alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes); | |||
| // Code implemented in JackAlsaDriver.cpp | |||
| void ReadInput(); | |||
| void MonitorInputt(); | |||
| void ClearOutput(); | |||
| void WriteOutput(); | |||
| void SetTimet(jack_time_t time); | |||
| #endif /* __jack_alsa_driver_h__ */ | |||