diff --git a/CHANGES b/CHANGES index 87318476..4c97fddc 100644 --- a/CHANGES +++ b/CHANGES @@ -1,1278 +1,1279 @@ * fix for potential deadlock when canceling playback test dialog * workaround for MP3 files with wrong length information + * fixed race condition in RecordThread (queue handling) 18.07.70 [2018-03-24] * enabled support for high dpi displays (icon scaling) * show error message if no plugins were found and terminate * updated developer handbook * cleanup: removed unused feature to attach meta data to lists of tracks and ranges of samples * bugfix: label positions got messed up after sample rate conversion 18.03 [2017-11-13] * do not reset undo/redo information when saving blocks or selection only * ask for confirmation (Continue/Cancel) before doing a revert * switched on MP3 support per default * bugfix: crash in pulseaudio playback * fixed some untranslated menu entries of plugins (missing context) * bugfix for sporadic fail of libaudiofile when seeking at EOF * improved C++11 compatibility 17.08.2 [2017-10-08] * new plugin: export to K3b project file * reduced flicker of position widget * bugfix: deleting labels per menu did not work * bugfix: wrong text in file progress dialog when saving * bugfix: compression type lookup did not work when using static functions * bugfix: distinguish ogg/vorbis and ogg/opus by mime type * changed license of audio samples to CC BY-SA 4.0 17.04.0 [2017-03-19] * use KDE versioning scheme * removed kwave.lsm and some now unneeded scripts (filter-pot.pl, get_lsm_entry.pl and set_version.sh) * simplified version number handling * eliminated cmake/FindOggVorbis.cmake * changed licenses of all cmake files to BSD license * bugfix: wrong assert in Stripe.cpp * OggOpus decoder: fixed unwanted data duplication (may lead to out-of-memory) * saveblocks: special handling for slashes in parts of a generated file name, e.g. title or meta data item - replace with similar unicode character * saveblocks: special handling for (multiple) whitespaces in parts of a generated file name - replace with single spaces * saveblocks: do not ask on every file in case that not all file properties are supported by the chosen encoder * saveblocks: use the block title (description of the left side label) as tile of saved block * bugfix: file was left in "modified" state after adding a label and canceling * re-activated the "label" menu * renamed command "add_label" -> "label:add" * renamed command "delete_label" -> "label:delete" * renamed command "edit_label" -> "label:edit" * implemented loading and saving of labels * allow special value -1 as index for label:delete(...) to delete _all_ labels * doc: split off developer sections from handbook into separate file, to reduce load of translators. new make target "html_doc_devel" (included in "apidoc") * label edit: avoid position from snapping too much away when adding a label in the gui while last edit was in percent mode * implemented moving of labels per mouse * show cursor line for orientation during drag&drop 16.12.0 [2016-11-28] * project moved from kdereview to kdemultimedia * added genre types 126..191 * record plugin: fixed crash when restarting record in MDI or tab mode * record plugin: reset did not work when clicking the "New" button shortly after starting the recording * record plugin: selection of default recording method did not work * revised use of signal handler in WorkerThread * WorkerThread: no longer use "bool" for signaling the wish to terminate, use QAtomicInt instead (also applies to Plugin class) * changed order of application object creation and setting up command line parser + about data * got rid of I18N_NOOP in main.cpp * bugfix: untranslated strings in menu * LICENSES file still mentioned Qt-4/KDE-4 libraries * CMakeLists.txt: remove RPATH settings * fixed small memory leak in menu group handling * fixed i18n of application AboutData * bugfix: internal name of "goto" plugin was wrong * bugfix: wrapper script did not work * fixed wrong encoding of error messages received via strerror and libs * bugfix: handling of File/Revert was wrong in case of newly created file 0.9.2 [2016-06-26] * recording via Qt Multimedia * using KDE service API for loading plugins * bugfix: screenshot function sometimes returned 1x1 image only (bug in Qt QWidget::frameGeometry is broken, but QWindow::frameGeometry works) * Gentoo ebuild updated to EAPI=6 * removed unneeded build and runtime dependencies * removed optimized memcpy for PowerPC * record plugin: improved handling of error messages * record plugin: added retry mechanism in case of device busy * added menu entries for recording and record setup * import of Core Audio Format (*.caf), using ALAC, A-LAW, U-LAW and IMA compression * import of Sample Vision Format (*.smp) * import of NIST SPHERE Audio File Format (*.nist) * import of Creative Voice files (*.voc) * import Audio Visual Research File Format (*.avr) * import of Amiga IFF/8SVX Sound File Format (*.8svx) * handbook: description of parameters of the record plugin was missing * handbook: fixed duplicate ":" in header of plugin parameter descriptions * made Kwave::SampleFormat and Kwave::Compression independent from libaudiofile 0.9.1 [2016-02-21] * ported to KDE Frameworks 5 (KF5) / Qt5 * playback via Qt Multimedia * bugfix: saved plugin parameter lists with escaped characters were not unescaped when loading again * compile fix for armv7l * codec_mp3: added missing "help" button to encoder setup dialog * fixed invocation of file dialog, as suggested by EBN * support for cmake > 3.3, fix for policy CMP0063 * cmdline option "--nofork" no longer exists * bugfix: multiple issues in context of switching the GUI type in scripts * bugfix: fixed issues in saveblocks plugin with special characters in filenames and patterns, format strings of second and later invocations of patterns were ignored * saveblocks: allow path separators in filename patterns to make it possible to create subdirectories * saveblocks: added patterns to include file info (file meta data) or the title of the current block * workaround for bug in KDE #345320 (missing translators in help/about dialog) * about plugin: added info about translation team * added screenshot of the edit_label dialog * bugfix: tooltips of the fileinfo dialog were not translated * new make target: "make msgstats" to show the progress of translations * compile fix for armv7l * playback: dropped Phonon support (was broken and no longer supported by KF5) * bugfix: hourglass cursor was not taken back in playback setup dialog * RPM: format of changelog has changed * changed plugin install directory and prefix/suffix * curve widget: use same colors as in frequency response widget, for better readability on bright color themes 0.9.0 [2015-05-25] * first version hosted on KDE (kdereview) and SourceForge * added command line parameter for selecting the GUI type * in MDI mode: new menu entry + function to arrange sub windows vertically * handbook: added text command reference * handbook: added plugin reference * enabled the "Help" buttons of all plugins and let them open the corresponding section in the handbook * make system: new target "update-handbook" (updates command, file info and plugin cross references) * make system: fixed dependency problem in translation * new commands: "window:sendkey", "window:screenshot", "window:close" and "window:resize" * built-in variable ${LANG} for kwave commands * support for delayed command execution * debug plugin: always compiled in, but only visible in debug build * new command sync(): wait for commands scheduled with delayed * bugfix: exporting a mono file as MP3 produced a stereo MP3 file * MP3: emphasis, copyrighted, original got lost during save/load * file info dialog: MPEG settings were not handled properly * bugfix: assert/numeric overflow in selectnextlabels() at end of file * new plugin: stringenter * bugfix: minimized windows were not migrated properly when switching GUI type * new command: window:minimize * bugfix: missing range check in noise generator (when used per script) * bugfix: saveblocks plugin did not work when omitting file extension * saveblocks plugin: use escaped strings for storing settings instead of base64 0.8.99-2 [2015-01-02] * bugfix: wrong sub window mode when switching to tab mode when having only one sub window (workaround for bug in Qt) * bugfix: recording did not work in MDI and Tab mode (wrong file context) * bugfix: fixed passing a text command as first command line parameter * new commands: delayed, window:click, window:sendkey, window:close, window:resize, window:screenshot 0.8.99 [2014-12-28] * GUI: implemented SDI, MDI and Tab GUI modes * bugfix: deadlock in class Track * bugfix: segfault during shutdown of logger * bugfix: segfault when unloading plugins (on some systems) * bugfix: "zoom to selection" was not disabled if nothing was selected * bugfix: toolbar buttons for cut/copy/erase/delete did not properly get enabled/disabled on change of selection * bugfix: overview widget did not properly refresh after deleting all tracks * bugfix: assert in vorbis decoder when opening file with bitrate -1 * menu subsystem: added support for lists within a menu * menu subsystem: show/hide toplevel menu entries * menu subsystem: added support for exclusive selection (radio buttons) * menu subsystem: let KDE chose shortcuts automatically * added menu entry to clear "recently opened files" list * implemented URL scheme for passing text commands from the command line example: kwave --iconic --disable-splashscreen test.wav \ kwave:plugin%3Aexecute?normalize \ kwave:save \ kwave:quit * using perl scripts creating for i18n from menus.config and for getting entries from lsm files, no longer need awk, sort, uniq * creating menu translation template directly per perl script instead of generated dummy cpp file (requires "msgcat") * menu translations: assign a context to each menu entry * bugfix: division through zero on ogg files with invalid bitrate info * manual: added section about GUI types * i18n: translations were missing in kwave.desktop 0.8.12 [2014-06-04] * recording via PulseAudio, by Joerg-Christan Boehme * bugfix: "Close" button of the record dialog did not save settings * bugfix: amplify free plugin: untranslated action names in progress bar * bugfix: sonagram plugin did not honor the windowing function parameter * bugfix: coherency problems in overview cache * bugfix: metadata got lost after cut/undo/redo * bugfix: save/as check against overwriting existing files failed * bugfix: undo/redo did not work after recording * bugfix: signal was "modified" after canceled record (empty) / done * bugfix: wrong calculation of zoom and window geometry at startup * bugfix: wrong scaling of overview in sonagram window * bugfix: playback pointer did not update synchronously across tracks * bugfix: brought back support for optimized memcpy (from xine-lib) * updated memcpy.c + cpu detection, including AVX assembler support * new command line option: "--logfile=" for logging to a file * brought back the horizontal scroll bar * support for swap files to store undo data * speedup: too many copy-on-write operations, use more const data * improved robustness against out of memory situations * memory manager: added statistics for debugging * memory settings: only use up to 25% of process address space * internal cleanups: renamed openSampleReader -> openReader, fixed signature of Signal/SignalManager::openWriter * speedup: use stripe list instead of raw data for saving undo data * debug plugin: added functions "labels_at_stripes", "sawtooth_verify" and "dump_metadata" * automatic defragmentation of stripes * sonagram plugin: use Qt Concurrent framework -> more than factor 40 faster on a quad core cpu * got rid of KDE ThreadWeaver, replaced with Qt Concurrent framework * debug plugin: added function "fm_sweep" * workaround for broken WAV files with zeroed fact chunk * fixed many 32/64 bit issues * new build target "make wrapper": creates a wrapper script to start Kwave for test/debug purpose * new build target "make dep": creates a binary debian package (for personal use and testing purposes) * mouse wheel + Ctrl: zoom in/out aligns signal to mouse position * record plugin: level meter is always enabled, simplified dialog * PulseAudio playback: fixed wrong timeout calculation * requires at least Qt-4.7 + FLAC-1.2.0 0.8.11 [2013-11-24] * added spanish translation, provided by Carlos R. * bugfix: file names were not properly escaped in context of file/open, file/openrecent and drag&drop * bugfix: saveblocks() did not abort properly when pressing cancel * unclean shutdown of the file progress dialog when saving * noise plugin: add noise (mix) instead of overwrite, with adjustable level in percent or dB * pause button: change tooltip to "continue" if paused * new command line option: "--disable-splashscreen" * new command line option: "--iconic" to start minimized * fixed quoting errors in CMakeLists.txt (cmake-2.8.12 complained) * bugfix: ASCII encoder: escape special characters in meta data * implementation of ASCII import * memory settings: raised default memory limits * bugfix: crash in file info dialog / auto generate keywords * MP3 plugin: use ID3 tag TSSE for software version * ASCII codec: implemented support for labels 0.8.10 [2013-02-09] * file name cleanup: removed "Kwave" prefix * bugfix: added range checks for track selection commands * reverted changes in sample writer due to problems in debug mode (commits ee54660d4380d264b7346a904eff9dd8d8d00a93 and 6fba04db879ea7ae1fdf79141dd93d47f9c1d403) * bugfix: unwanted termination if splash screen closed while the first toplevel widget still was starting up * moved code into namespace "Kwave" * cleanup: remove support for outdated FLAC API versions below 1.1.3 * removed unused code: libkwave/FileFormat.* * renamed source files with "Kwave" in the name * added subsystem prefix to inclusion of Qt header files * using bit types from qt (e.g. u_int32_t => quint32) * compile with DQT_NO_CAST_TO_ASCII and QT_NO_CAST_FROM_ASCII * bugfix: recording via OSS did not handle invalid devices properly * improved auto detect of svg-to-png conversion, added support for "rsvg-convert" (SF bug #38) * removed dependency to ImageMagick if "rsvg" is available * replaced libkwave/byteswap.h with generic Qt functions * replaced some Qt classes with their KDE equivalent: KLineEdit, KComboBox, KDialogButtonBox, KPushButton, KTabWidget, KTextEdit * using KDE standard buttons in dialogs * simplified plugin loading mechanism, do load/unload only at start/end of the program * delete plugin settings of old versions when detected * using QLibrary instead of functions from libdl * bugfix: shutdown sequence was incomplete * bugfix: keyboard shortcut for first menu entry did not work * bugfix: ambiguous keyboard shortcut for "File/New Window" * bugfix: undo of "modify label" caused loss of other labels * bugfix: use timeout for phonon playback, to avoid hang on unusable devices * using klocale for formating numbers of samples * added common base class for all codec plugins * reduced quality level of sample rate converter from "best" to "medium", to improve speed * refactored playback handling (controller vs. plugin) * workaround for bug in Phonon: no device names available in first call to Phonon::BackendCapabilities::availableAudioOutputDevices() * moved playback test into worker thread, for better GUI responsiveness * Phonon playback: changed to own mainloop with timeout support to avoid application hang on broken audio devices * bugfix: data loss in sample rate converter when processing streams * vorbis encoder: call to deprecated API (now use OV_ECTL_RATEMANAGE2_SET) * using estimated length for streaming file formats without length info * made sample rate conversion (libsamplerate) mandantory * increased default memory sizes * added toolbar buttons for "File/SaveAs" and "File/Close" * reordered toolbars 0.8.9 [2012-11-06] * new feature: MP3 export via external program "lame", "toolame" and "twolame", with configurable command line options * new feature: allow change of compression type via file info * fix for SF #3528848, removed -Wl,--add-needed from plugin LINK_FLAGS * speedup: improved performance of sample writer * wav import/export: support for some more meta data tags * bugfix: meta data lost when writing wav files that had meta data for product/album or subject/track at the same time * bugfix: broken signal/slot connection in SaveBlocks plugin * workaround for bug in id3lib, SF #3534143: ignore id3lib crc check result for MPEG Layer II files * bugfix: Gentoo ebuild lacked required svg use flag for media-gfx/imagemagick and media-gfx/graphicsmagick * bugfix: File/SaveAs now uses last recently used directory and extension together with the user defined file name * bugfix: PluginManager::sync caused application slowdown or stale GUI 0.8.8 [2012-05-20] * new feature: seek functionality for playback * new feature: added toolbar with record/playback/scroll functions * migration to GIT as source code management * documentation update * allowing zoom and scroll while a plugin is running * allow "close" and "quit" while playback is running * allow track selection change during playback * fix for namespace collision with libaudiofile * bugfix: mouse selection update with negative offset failed * bugfix: wrong focus of progress dialog when repairing damaged wav files * bugfix: missing updates of zoom selection combo box * bugfix: when viewing with full zoom, scroll by 1 sample was possible * bugfix: focus was wrong on program start (zoom combo box) * bugfix: wrong view when moving slider of overview widget to negative value * bugfix: playback pointer did not disappear after play - pause - stop * bugfix: creating a label without text was not possible * bugfix: saving WAV with G.711 and non-16bits/sample produced broken output * bugfix: handling of shortened tracks in encoders 0.8.7 [2011-11-27] * ebuild update for media-gfx/imagemagick <-> media-gfx/graphicsmagick (see gentoo bug #314325) * new feature: "insert at", paste clipboard at given position * fix for API change in libaudiofile v0.3.1 * speedup: loading ogg/mp3 is much faster now (up to factor 2) * bugfix: stream name of pulse audio playback used wrong encoding * update of the Kwave spec file (synced with OpenSuSE build service version) * new build target "distfiles" * updated version of the GPL v2 document (GNU-LICENSE) * support for visualization plugins 0.8.6 [2011-03-07] * bugfix: copy/paste with partial track selection failed * bugfix: labels update after undo of copy&paste failed on multitrack signals * string/i18n update from Panagiotis Papadopoulos * bugfix: invocation of xgettext was wrong, left untranslated strings * plugin API change: support for translateable short description * about plugin: use plugin info from PluginManager * bugfix: last directory of file dialogs sometimes got lost * bugfix: wrong message when canceling Ogg import * replaced sched_yield() with QThread::yieldCurrentThread() * added cmake parameter for disabling optimized memcpy support -D WITH_OPTIMIZED_MEMCPY=OFF, default is ON * integrated patch #3021795 for Qt-4.7 compatibility * bugfix: optimized memcpy for PPC (SF bug #3068664) * doc: upgrade to DocBook XML V4.2 / V1.1 * build fixes for qt-4.7 * no longer using QSplashScreen (has side effects, operates as modal window) * bugfix: startup as unique application did not work correctly * bugfix: potential crash in message loop of progress dialog * bugfix: handling of track selection was wrong in reverse plugin * workaround for bug in libaudiofile: some files have sampe rate zero, falling back to 8000 samples/sec in that case (audio/x-ircam, sun, BE) * bugfix: reverse failed on files smaller than the internal block size * using entities for URLs in handbook, to simplify maintenance * bugfix in cmake files: some invocations of STREQUAL lacked quotes 0.8.5 [2009-12-24] * new feature: playback via PulseAudio * applied kwave-0.8.2-nolinguas.patch (see gentoo bug #267702) * support for the Gentoo build system that steals .po files * no longer default to english language for documentation and gui l10n * fixed use count mismatch of plugins * bugfix: playback control: continuing after pause continued from start * bugfix: G.711 encoded wav files support only 16 bit signed format * new assignment for mouse wheel: - without modifier key: scroll left/right - with Shift: page left/right - with Ctrl: zoom in/out - with Alt: vertical zoom in/out * bugfix: support sysinfo.mem_unit when >= 4GB RAM are installed * bugfix: crash in progress dialog handling (crashed when closing a plugin after finishing it's work) * new ebuild for Gentoo 0.8.4 [2009-09-26] * new feature: support for primitive macros (batch files), playback only * new plugin: change sample rate * using libsamplerate (new dependency) * new feature: sample rate conversion on clipboard data * new feature: ability to set recording start time in advance (feature requested by John David Thompson) * bugfix: drag&drop of files on the main window was broken * workaround for bug in id3lib which crashed in ID3_Tag::GetSize() with some MP3 files (see id3lib upstream bug at SF #2821464) * bugfix: recording via ALSA, crash on snd_pcm_close(), see SF bug #2816544 * bugfix: playback plugin: infinite loop when switching from OSS to ALSA * bugfix: forcing clipboard and drag&drop data to uncompressed mode * bugfix: deadlock in progress bar handling * bugfix: crash when unloading plugins with queued events * help/about dialog: hide "translators" tab if no translator available * help/about dialog: hack to allow web addresses of translators * bugfix: selection was not set after "paste" and undo of other operations * bugfix: label handling in context of "delete" and "undo" was broken * bugfix: invalidation of overview cache after delete was not correct * bugfix: artifacts in track display in min/max overview mode * bugfix: add/delete/modify of labels did not set the state of the current file to "modified" * bugfix: record dialog caused shutdown to hang when closed while recording * bugfix: decoding 32bit/sample was broken * bugfix: recording level meter consumed 100% cpu * new make target: "make apidoc" for internal doxygen documentation * bugfix: some images and icons in non-english documentation were missing * volume plugin: preview was not updated on first use of plugin 0.8.3-2 [2009-07-04] * bugfix: re-enabled detection of optimized memcpy function * bugfix: deadlock in recording plugin and plugin management (see SF bug #2816544) * bugfix: ID3 tag import did not work * taking ID3 tag for "album" as "product" in wav meta data * taking ID3 tag for "track" as "subject" in wav meta data 0.8.3 [2009-06-28] * integrated 05-do-not-install-so-symlinks.diff from Debian (thanks to Aurelien) * cs i18n update from Pavel Fric * new plugin: normalize * progress bar in volume plugin did not work * flattened "Fx" menu, no submenus for amplify and filter * bugfix: workaround for libaudiofile bug produced wrong header in 24bit/sample mode * bugfix: "fade outro" was broken * bugfix: the dialog when playing the test sound in the playback setup dialog did not appear * replaced qreal with double (fixes build problems on arm) * show hourglass / progress bar when undo/redo is running * flattened "Calculate" menu, no submenus for "Frequencies" * wav encoder: auto-switch to unsigned format for <= 8bit and signed format for > 8 bit per sample * volume plugin: show a little "preview" for guessing the level * bugfix: after deleting a track, file info was not updated * about plugin: separate tab for translators * made plugin API version configurable per plugin * recognize mime type "audio/x-vorbis+ogg" (found in KDE-4) * updated czech gui translation and user manual from Pavel Fric * bugfix: crashes when deleting objects that still have event queued with Qt::QueuedConnection -> now using Qt::BlockingQueuedConnection * new plugin: reverse * speedup: limiting the number of progress bar updates per second * memory manager: fixed multithreading issues, improved OOM behavior * bugfix: received SIGBUS in SwapFile when disk was full * improved performance of memory management * require Qt4 v4.5.0 or newer 0.8.2 [2009-04-25] * bugfix: minor off-by-one bug in buffer handling * wav/RIFF parser: be more robust if the file has not been correctly padded * bugfix in wav encoder: padding for info and label chunk was missing * bugfix: if two markers were too close and displayed at the same pixel position they eliminated each other through XOR mode * bugfix: numeric overflow when trying to select labels in high zoom factors * bugfix: not all positions were selectable due to internal rounding errors * silence plugin now supports all modes * use "unsigned" sample format per default when creating new files with <= 8 bits/sample * bugfix: playback position was shown on startup * bugfix: show correct file size in progress dialog * bugfix: crash when deleting label from end of signal * bugfix: overview was wrong when deleted space after signal was visible * bugfix: overview was not always synchronized after delete/insert * bugfix: "modified" state got lost during undo * use ALSA per default for playback/record if nothing has been selected yet * fixed calculation of undo/redo sizes * undo/redo handling for sample range and track selection * processing updates of overview widget in a background thread * memory management: no longer evaluate RLIMIT_RSS, gives more available physical memory * portability fix: swapfile creation/destruction went wrong * feature: memory for undo/redo can now be configured * bugfix: handling of "continue without undo" produced wrong undo/redo states and asked several times * bugfix: file progress did not do GUI updates, cancel button did not work * bugfix: assert in record plugin if no valid sample rate available * speedup for generation of signal overviews in min/max mode * bugfix: MultiTrackWriter produced one extra sample (off by one error) * workaround for bug in libaudiofile: sometimes libaudiofile produces broken files as it uses 'float' for internal calculations (wrong size of 'data' and 'RIFF' chunk) => see ubuntu bug #327018 * implemented "debug" plugin, with internal functions for test and verification (quality improvement) * added czech gui translation from Pavel Fric * bugfix: after creating a new empty file, "revert" was possible * speed optimizations in buffer handling * speedup: limiting the rate of progress updates when loading and saving files * fixed displayed names of actions based on the "amplifyfree" plugin * bugfix: menu entry translation did not work correctly * bugfix: deleteLater on menu nodes did not work, implemented own garbage collector * speedup: use different block sizes for interactive and non-interactive mode * i18n fix: texts in help/about menu were untranslated * about plugin: new tab for translators 0.8.1 [2008-12-23] * replaced application icon, now using a scalable svg image * replaced GSL with FFTW3, which is license compatible with Kwave * use implicit sharing for Label class * new clipboard implementation, using the clipboard of KDE (X11) * fixed enable/disable of copy/paste functions depending on clipboard state * re-enabled function "flush clipboard" * re-enabled function "invert track selection" * re-enabled function "select all tracks" * implemented plugin for "go to position..." * added status bar item for current cursor position * show current playback position in status bar * show selection in overview widget * bugfix: mode switch in time selection widget did not work properly * bugfix: handle situation when adding or moving a label to a location that is already occupied by another label * show labels in overview widget * show current playback position in overview widget * overview widget: dimming parts that are out of view * no longer needing built in copy of libaudiofile, removed 0.8.0 [2008-09-27] * ported to KDE4 / Qt4 * dropped support for FLAC API v1.1.1 and older * support for ALSA lib API v1.0.16 * made MP3 decoder disabled per default due to legal issues * fixed bug in cue list parsing of .wav files * fixed bugs in recording plugin, recorded too much if recording time limit was activated or in prerecording mode * a much nicer splash screen * bugfix in label handling: support labels with zero-length names * re-arranged source files for cleaner library interfaces * re-enabled accelerator keys for 0..9 * using horizontal scrollbar instead of overview widget * implemented vertical zoom (Ctrl + MouseWheelUp/Down) * using more standard KDE keyboard shortcuts * nicer icons for the menus * using more icons from the crystal icon collection (to clearify the license situation) * removed aRts support * now also available through the openSUSE build service for various platforms * respect the LINGUAS environment variable to build only needed languages (defaulting to all) * removed changelog from online manual to simplify the work of translators * no longer dependent from "recode" * recording plugin: show current recording time in status bar * fixed infinite loop on undo/redo of channel selection * usage of GSL can be disabled through cmake parameter -DWITH_GSL=OFF * support for OSS v4 (integrated sf feature request #1870434) 0.7.11 [2007-12-09] * new internal streaming architecture, based on Qt instead of aRts * aRts support is now disabled per default * some minor bugfixes for x86_64 support * band pass plugin 0.7.10 [2007-08-08] * build system: using 'METASOURCES=AUTO' (which simplifies a lot) * ported the build system to cmake * support for newer APIs of FLAC v1.1.3 and v1.1.4 (closes SF bugs #1713655 and #1757716 + debian bugs #427747, #426668 and #431199) * replaced problematic code in libaudiofile with new code under the LGPL, contributed by Bertrand Songis (partially fixes debian bug #419124) * update of the online documentation to reflect the change of the make system 0.7.9 [2007-05-01] * playback via ALSA: offer the "default" device, if no devices found offer the "null" device * implemented import and export of labels, currently only for uncompressed wav files * new plugin for saving blocks between labels as separate files * new function: expand selection to labels * new function: select next/previous range between labels * bugfix: don't change the file name when saving only the selection * new configure option: --enable-doc=yes/no to enable/disable the generation of the online documentation (default=yes) 0.7.8 [2006-12-31] * bugfix: workaround for bug in ALSA, crashed when initializing the dsnoop plugin * bugfix: error in swap file handling, one sample was destroyed when resizing. Affects cut, delete, crop and many other functions. * fixed the incorrect usage of the word "loose" (thanks to J.T. Hundley) * bugfix: went back to old implementation of ThreadsafeX11Guard class in order to fix a deadlock (closes sourceforge bug #1623357) * documentation update: mention Subversion instead of CVS * zero plugin: new mode, support for inserting a range filled with silence * fixed the macro functions "Fade Leadin" and "Fade Leadout", using the new mode of the 'zero' plugin * export of ASCII format files 0.7.7 [2006-09-17] * new feature: implemented a small widget that shows the current selection position and the selection borders * new feature: context menu for the signal widget (right mouse button) * improved file open dialog: show "All Files" and "All Supported Files" * bugfix: error in handling of mouse selection * bugfix: recording only used the first channel (closes sourceforge bug #1551050) * install plugins kde_moduledir/plugins/kwave instead of kde_datadir/kwave/plugins 0.7.6 [2006-06-05] * bugfix: recording setup crashed when called for the first time * bugfix: do no longer crash when recording device is not present or opening failed * bugfix: fixed generation of rpm dependency for libmad * bugfix: update the size of the level meter if the dialog size has changed * record plugin: added a fancy status bar * record plugin: added autodetect/scanning for OSS devices * record plugin: added dsnoop plugin as ALSA source * record plugin: fewer annoying message boxes, instead show a short notice in the status bar for some seconds * record plugin: add logarithmic scale to the level meter and use 3 colors * playback plugin: added autodetect/scanning for OSS devices * playback plugin / ALSA: support for 18 and 20 bits/sample * playback plugin / ALSA: support for big endian 0.7.5 [2005-12-31] * draw signal in a different color set when not selected * bugfix: solved deadlock situation when starting a plugin while another plugin was still running * workaround for deadlock when trying to close the current file while a plugin is still running * bugfix: delete range only in selected tracks * thrown over board the idea of using gstreamer due to serious license issues, we will wait until KDEMM is out (KDE-4) instead. 0.7.4 [2005-10-16] * recording via ALSA * support for the silently changed API of libFLAC++ v1.1.2 (closes sourceforge bug #1243707 + debian bug #289953) * fixed support of MMX / SSE detection on X64_64 architecture (closes sourceforge bug #1244320 and debian bugs #288781 + #327501) * decided to support gstreamer as streaming engine in future versions (will make v0.8 if Kwave is aRts-free) * fixed some German translations (closes debian bug #313790 and bug #314000) 0.7.3 [2005-05-26] * playback via ALSA * completely new playback settings dialog, with support for aRts, ALSA and OSS * playback plugin: play a test sound * record plugin: detect when device is alread open, now no longer blocks. Show an error message. * smoother signal display in overview mode (no gaps) and improved polyline mode * replaced some of Kwave's multithreading classes with classes from Qt * compiles under SuSE-9.3 * ebuild file for Gentoo Linux 0.7.2 [2004-12-31] * big rework of the internal streaming/storage subsystem, support for multiple stripes. Makes a big speedup when handling large files! Creating an empty 512MB file before: over 350 sec, now: about 25 sec (on my system) * optimized versions of memcpy() for ix86 (using MMX, MMXEXT, 3DNOW, SSE, SSE2) and for PowerPC, copied from the xine project * some support for X86_64 * bugfix: in memory setup plugin, set virtual memory limit only if the limit has been enabled (checkbox is clicked) * bugfix: clipping in Ogg import filter was incorrect * speedups: import of Ogg and MP3 files improved * removed code copied from the GSL library, link against the shared library instead * added target "package-messages" to the toplevel Makefile, for translators 0.7.1 [2004-07-10] * FLAC (Free Lossness Audio Codec) import/export plugin * speedups for loading / saving files * removed our own copy of libmad from the source tree, now it should be available in all common distributions * implemented pre-recording * implemented recording time limit * bugfix: minor bug in the recording state machine * bugfix: solved some layout issues in the about- and sonagram plugins * bugfix: cancel while saving to .ogg works now * update of the online documentation, many screenshots * improved Makefile dependencies of the plugins, now parallel builds also work and speed up the creation of plugins 0.7.0 [2003-12-01] * first version with recording functionality (still alpha) * removed workaround for uic invocation * bugfix: handling of persistent and unique plugins was wrong, which caused playback to work only in the first main window instance * added project files for kdevelop-3 0.6.7 [2003-06-28] * new plugin: "pitch_shift" * new plugin: "lowpass" * new plugin: "notch_filter", contrinuted by Dave Flogeras * included a bugfixed version of the synth_pitch_shift aRts plugin * new feature: "pre-listen", first implementation in pitch_shift plugin * ported to work with Qt-3.1 without Qt-2 compatibility, also compiles with -DQT_NO_COMPAT -DQT_CLEAN_NAMESPACE 0.6.6 [2003-03-29] * works with KDE-3.1 * many improvements on the build system. Now compiles under Debian, Mandrake, RedHat, Gentoo and SuSE * starting up with last window size * Xt toolkit option for geometry works again, including workaround for bug in KDE3's geometry management. example: "kwave -geometry 800x600" * bugfix: select to left selected one sample less then needed * volume plugin: simple clipping * volume plugin: mode for "multiply with /divide through factor" * newsignal and selectrange plugin: got rid of KDoubleNumInput and it's weird display and entry behavior * selectrange plugin: also select start position of selection * can use libmad and libaudiofile from the host system if usable * show the fileinfo plugin when saving under a different mime type 0.6.5 [2002-11-09] * MP3 import with ID3 tag support through id3lib and libmad * Ogg/Vorbis import and export (only ABR mode) * new plugin "volume" * show selected range as time (feature requested by Christian Hollaender) * support for saving compressed .wav files * thrown away Qt2/KDE2 compatibility, now only supports Qt3/KDE3 * playback plugin: enabled the "select..." button for choosing other playback devices (feature requested by Len Ovens) * solved problem with name mangling in plugins and different gcc versions * works with gcc-3.2 / solved __dso_handle problem * stricter checks for programs in configure script 0.6.4 [2002-06-30] * support for different file formats / integrated libaudiofile * drag and drop bugfix: dropping into the same signal left from the selection removed wrong range * auto-repair for structurally damaged wav files * bugfix: save selection works again * integrated libkwavemt into libkwave * using time instead of zoom factor, e.g. set zoom to "1 minute" (feature requested by Gilles Caulier) * menu entries for playback control * some more icons in the menus * replaced KFileDialog with subclass KwaveFileDialog (works around some bugs in KDE) * added a little chapter about digital audio basics to online help * added "select range" plugin 0.6.3 [2002-03-01] * simple drag and drop * french translation * handling of "signal modified" * shows error message and aborts if loading failed 0.6.2 [2001-12-24] * new plugin "amplifyfree" * new plugin "noise" * >>> new aRts plugin adapter framework <<< now Kwave is able to use existing aRts plugins in it's own plugins for sound processing * changed documentation to XML / Docbook-4.1 * recovery of damaged files if non-zero file length but data length entry in the wav header is zero (e.g. happens when krecord crashes during recording) * bugfix: freeing virtual memory fixed in MemoryManager * bugfix: problem with TSS in TSS_Object cleanup 0.6.1-1 [2001-09-01] * bugfix: class Track made duplicate entry in stripe list when inserting signals into an empty track * fixed that weird layout behavior in dialogs, seems that Qt has problems with complex nested layouts :( 0.6.1 [2001-08-24] * >>> USE OF VIRTUAL MEMORY <<< * changed Makefiles: html docu stays in distribution due to too much trouble with the KDE documentation tools * when inserting from clipboard into a signal with a different number of tracks, the result will be mixed (still not optimized/slow) * fixed compile problem with gcc-2.96 / gcc-3.0 * fixed missing header file in NewSigDlg.ui * the RPM should be relocatable again * fixed bug in shutdown sequence, now clipboard is flushed before the application closes. 0.6.0 [2001-07-29] * >>> PORTED TO QT-2 AND KDE2 <<< * completely new internal architecture * plugins can be located in a user directory * libkwave is included and no longer supported (at least by me) as a separate package * playback via aRts * many more bugfixes, too many to mention here... 0.5.5-1 [2001-02-23] * bugfix: selection across end of file no longer possible * bugfix: no overflow in wav header when saving large wav files above 268MB (bug reported by Sven-Steffen Arndt, ssa29@gmx.de ) 0.5.5 [2000-12-01] * new playback handling, allows pause/continue * limited the playback buffer to be between 256 and 65536 bytes due to problems (system hang) with small playback buffers with 16..64 bytes (might be a hardware problem) * introduced a toolbar for some standard operations * fixed some bugs concerning selection with the mouse * rework of the overview widget (used in main window and sonagram) * fixed menu command "zoom selection" * sonagram: saving to file, auto-brightness adjust * replaced QFileDialog with KFileDialog * tested with AMD Athlon-optimized compiler (patched pegcs) * some fixes for safer multithreading * checking for much more header files at configure time (due to a problem reported by issiac@evcom.net ) 0.5.4-4 [2000-10-03] * added classes Mutex and MutexGuard * sonagram: set a transparent background for the image * added sizeHint() and minimumSize() to ScaleWidget and OverViewWidget * sonagram: removed (need for) SonagramContainer, using QGridLayout instead * moved SignalProxy to the mt subdirectory * fixed X11 synchronization problem with SignalProxy * added TSS (thread-specific-storage) support to the mt classes * added some multithreading support classes: Thread, AsynchObject, ... * removed the "get" prefix from all member functions. This is the new KDE/QT coding style. * updated the online documentation to point to the new Kwave homepage on http://kwave.sourceforge.net/ * class ImageView: always repaints (maybe image data has changed) * bugfix: selection and playpointer will not be drawn if no signal is loaded 0.5.4-3 [2000-09-09] * the sonagram window updates it's title if the signal's name changed * found a solution for the problem of synchronizing X11 and QT in a multithreaded environment * fixed bug in the "Halt" function (playback) 0.5.4-2 [2000-08-20] * geometry/layout management for the MainWidget * limited the displayed height of a signal. If not all signals fit onto the screen, a scrollbar appears on the right side of the signal. * limited the size of the TopWidget to a reasonable minimum size * automatic dependencies for the plugins work again 0.5.4-1 [2000-07-29] * fixed layout of playback dialog * started to implement a new plugin interface * geometry/layout management for the sonagram settings dialog * formatting of selection and file time (KwavePlugin::ms2string) * plugins can now consist of multiple source files 0.5.4 [2000-07-12] * some more minor changes to the Makefiles * split the documentation output into "de" and "en" part * made symbolic links to the english help directory from the "de" and "default" directory during make install and uninstall and also in the post and postun scripts of the specfile The user should at least get the english help... * alpha version of english documentation done * automatic update of the revision history in the docbook file if this file is modified (only english version) * CVS is up on sourceforge.net * changed some header lines in this file * started on writing a new documentation / online help using docbook 0.5.3 [2000-06-12] * if a file with invalid size (e.g. recorded by "arecord") is loaded, shows a message and truncates the input at the end of the file * found out that we need ALSA support for 24 and 32 bits/sample * >>> playback in stereo <<< * selected channels (x) are mixed to the output device's channels (y) at playback using a x:y translation matrix with linear scaling, all values for x and y except zero are allowed * playback only for selected channels * rework of the settings/playback dialog (plugin) * heavy reword on the playback code * fixed severe bug in SignalManager::readWavChunk(), chrashed if there was data after the wav chunk 0.5.2-12 [2000-06-02] * copied the AsyncSync class into libgui, should be used for threadsafe usage of the qt library * moved handling of the "selected" flag from class SignalManager to class Signal * fixed selection of channels if appended or deleted 0.5.2-11 [2000-05-28] * included config.h in each source file (except the plugins) * export to ASCII for multi-channel signal (multi-channel import has still to be done, currently only mono) * fixed many memory leaks and inconsistent delete operations (e.g. used "delete" instead of "delete[]") * included support for (and tested with) the error detection and memory debugging tool "Insure++ Lite 4.1" (./configure --enable-insure=yes ...) -> thanks to ParaSoft Corporation for making this limited version of the tool available (http://www.parasoft.com) * SignalWidget uses three layers for drawing, speeds up the redraws after mouse selection by about factor 14(!!!) on my system :-)) 0.5.2-10 [2000-05-21] * some minor bugfixes in the Makefiles * save the kwave.spec and include it into the source archive, this lets "rpm -ta kwave-x.x.x-x.tar.gz" work * wrote a new README file, moved Martin's version to README.OLD * RPM_OPT_FLAGS are appended to the compiler options, this lets pentium optimizations work :-) * shows a message box if loading of a file failed 0.5.2-9 [2000-05-19] * list of recent files is synchronized across all toplevel windows * fixed dozens of memory leaks, missing ASSERT constructions, missing variable initializations and possible divisions through zero * Help menu aligned to the right side (MenuRoot now is able to process the special command "#separator") 0.5.2-8 [2000-05-18] * replaced all occurances of sprintf with snprintf, strcpy with strncpy (in 92 places) ! * doesn't show any zoom factor if no signal is loaded * handling of channel add/delete: selection/speakers are shifted * changed some variables/parameters to "unsigned" (simplifies range checks) * beautified this file * beautified the whole source code according to my favorite coding style. -> thanks to the developers of the "Artistic Style" package, astyle-1.11.4-1 made good work :-) * fixed that annoying flicker in the help/about dialog * checking for sizes of char, short and int at configure time * globals.app will not be used (obsolete, should be removed from libkwave) * MessagePort will not be used (obsolete, should be removed from libkwave) * multiple toplevel windows are possible * made X toolkit parameters work (especially "-geometry") * bugfix concerning loading/saving 8 bit .wav-files (always unsigned !) * >>> COMPLETE REWORK OF THE INTERNAL COMMAND STRUCTURE <<< - made use of a combination of signals/slots and string messages - hierarchical processing: commands are are forwarded "upwards" until they reach a TopWidget - the TopWidget (highest level) dispatches the commands and forwards them to the lower levels 0.5.2 [2000-04-24] * rpm package should now be installable without conflicts and compile without any previous installation of kwave * removed the "${KDEDIR}/share/doc/HTML/default" directory from the rpm so that it doesn't conflict with the already existing one * shift+Home/shift+End selects from the current left/right position up to the start/end of the signal * bugfix in display of signal: signal is no longer inverted * selectrange() works now * the zoom factor combo box reflects the current "real" zoom factor * some bugfixes in menu handling / cleanups * complete rework of zoom and offset handling: - simple poly-lines instead of lowpass interpolation if zoom factor has less than 10 pixels per sample - lowpass interpolation if more than 10 pixels per sample * bugfix in KWaveApp: now sets globals.app to this if it was null before, now doesn't crash if it loads a file specified at cmdline 0.5.1-4 [2000-04-16] * >>> now compiles and runs under RedHat 6.1 / Halloween IV <<< >>> as well as under SuSE 6.2 <<< * version info of libkwavegui.so is set to the package's version * bugfix in plugins/template/Makefile.am: will not create .moc files on make distclean and other targets * compiler flags are passed through to plugin compilation * compiling with --no-rtti. This was necessary to compile against the kde libraries of RedHat that seem to contain no rtti. As a side effect all warnings on linking programs/libs disappeared :-) * configure-parameter --enable-debug has effect again * >>> ASCII import and export works now (mono only) <<< * bugfixes in some plugins, all compile now without warnings/errors * plugins are processed in alphabetical order * all plugins are automatically found and compiled * new target "make src.rpm" makes only the source rpm 0.5.1-3 [2000-04-03] * display will be scrolled left or zoomed if something from the end of the signal is deleted * curve parameters of fade in / fade out work again 0.5.1-2 [2000-03-16] * converted many "klocale->translate(...)"s into "i18n(...)" * target "make messages" works again * converter for menus.config, creates a dummy .cpp-file that is handled by i18n 0.5.1-1 [2000-03-13] * new target "make rpm" creates binary and source RPM packages * fixed the shared-library-problem in the build system 0.5.1 [2000-02-28] * menu items can belong to groups * renamed SignalWidget::info to "refresh" * many cleanups in the header-Files in src and libgui * the menu management has completely been rewritten: - Menu, NumberedMenu and MenuCommand classes are deleted - new classes: MenuNode, MenuItem, MenuSub, MenuToplevel and MenuRoot * menu items can have icons * menu nodes can have unique string ids * special menu commands start with a "#" * first attempts for internationalization * list of recent files is sorted by time of last usage 0.5.0-1 [1999-12-27] * moved my modifications from the Makefiles to Makefile.am * included targets "make release", "make patchlevel" and some scripts 1999-12-19 (by Thomas.Eschenbacher@gmx.de) * remade my modifications of some Makefiles and of the configure script that were lost during Martin's changes * changed shortcut for mixpaste from CTRL-SHIFT-X to CTRL-SHIFT-C * added the "crop" command to the edit menu * made the "mixpaste" command work * corrected the call of "delete", now really deletes instead of cutting and copying the selection to the clipboard (saves clipboard content) 1999-12-18 (by Martin Wilz ) * changed filenames to reflect class names * one class per file is now the standard * stripped leading "Kwave" in class names for most classes 1999-12-10 (by Thomas.Eschenbacher@gmx.de) * removed -Werror compiler option (caused trouble with configure script) * fixed a nasty bug in SignalManager::save that caused crashes on several positions in the program and libstdc++ 1999-12-09 (by Thomas.Eschenbacher@gmx.de) * gave the destructor of SignalManager some code, this fixes a huge memory leak ! * added a TODO file * added -Werror to the c++ compiler options when debugging enabled * some include file cleanups in libgui 1999-12-07 (by Thomas.Eschenbacher@gmx.de) * SignalManager::writeWavChunk uses buffers for writing (much faster!) * bugfix: caption of main window changes after "SaveAs" * bugfix: selected resolution takes effect * bugfix: caption of main window changes after "SaveAs" * bugfix: SignalManager::writeWavChunk now doesn't destroy the signal's data while saving * make distclean in the projekt root directory also removes zero-length files, *.orig, *.rej and *~ (just makes cleaner than before) * symbolic links to Makefile, Makefile.in and Makefile.am in the plugins directory are deleted with "make distclean" and rebuilt on "make" (changes in the referenced Makefiles in the template directory will not be reflected thousand times when creating a patch with diff) * cleanups, removed some old backup files * improved support for debugging accessible through * "configure --enable-debug=yes" (-g and -DDEBUG compiler flags) * rewritten big parts of Makefile.in for the plugins * added -O2 compiler optimization 1999-12-03 (by Thomas.Eschenbacher@gmx.de) * merged with Martin Wilz's version 1999-11-12 (by Martin Wilz ) * version numbering script donated by Thomas Eschenbacher * now using KTMainwindow for top level widgets * using timer to check message port -> alternative (threadsafe) message passing instead of signal/slot * labeling code rewritten, now incompatible with old releases * batch loading routines 1999-09-07 (by Martin Wilz ) * deleting channels works again * fixed savelabel dialog * corrected envelope dialog, string handling * connected many functions via the new string-based way of invocation * fixed some dependencies between old code and new classes (there's still more to do !) * saving should now work again * trimmed down Clipboard class * Color class as wrapper to QColor (may become independent later) * reworking Curve Class for creation via string, interpolation now uses curve objects * moved gui functions into a new library (libkwavegui) * new Classes: Parser DynamicLoader Filter (previously was a struct) * moved gui-independent functions into a library (libkwave) * rework of dialogs into single files and single plugins * new calling scheme via string commands. This will allow scripting and macro definitions. Threading is made a whole lot easier, because a only a string has to be passed and gets expanded into the needed set of parameters in each thread * io functions and playback adapted to SignalManager * Introduction of SignalManager class for multiple channel management 0.29.5 [1998-12-25] (by Martin Wilz ) * Just a fix for an annoying bug while zooming out 0.29.4 [1998-12-22] (by Martin Wilz ) * removed a memory leak in playback * triple-checked the missing Accelerators in the Menumanager. It seems to be a bug in qpopmenu, I'll wait for qt to be fixed, or until a workaround is known * recent Files are updated again, while the program is running * kwave now keeps track of last directory saved to; for user convenience * reestablished selection mechanism to match versions before 0.29.3 and corrected some otherwise screwed-up behavior * _now_ all parameters to destructors should have vanished 0.29.3 [1998-12-18] (by Martin Wilz ) * developement has slowed down a bit, this release is not as complete as I wished but since 0.29.2 has a destructor with parameters accidentally left in, and so does not compile on all systems -> here we go again... * reworked selection routines into a new class, code is still rather confusing, but seems to work * added checkmark functionality again * converted file-menus to new menu-scheme * added gui to mix channels together, the needed functions for mixing are still missing * Halt button by Gerhard Zintel 0.29.2 [1998-12-15] (by Martin Wilz ) * moved clipboard functionality to its own class * dynamic allocation of menu entries used by all classes but TopWidget * import of ascii data files 0.29.1 [1998-12-13] (by Martin Wilz ) * Bugfix for multichannel save. Now the saved files should work with other prgs * local snap to peak by Gerhard Zintel 0.29.0 [1998-11-12] (by Martin Wilz ) * changed version numbering and filename as suggested by Version 1.1 of "How To Name Things" from sunsite. The last digit will always mark be 0 for releases uploaded to ftp.kde.org. * added windowing (Hamming Hanning, Blackmann) functions * contribution from Gerhard Zintel displaying notes in fftview * Added pitch display window * implemented cursor and db scale for fft-view * added reselection and cursor change * added possibility of different display modes in Frequency representation * fixed severe quantization bug in saving 16Bit routine, reported by ? * mmaping support contributed by Juhana Kouhia * added as new Possibility to generate Signals: pulse trains * added wrapper for systems with no posixthreads -> still needs handling by configure script (change Makefile for not linking libpthread and doing a define) * First use of multiple threads (pthreads) in some functions * Pitch generation now independent of additive synthesis * added import function for ascii files * Ascii label saving now also by frequency * Label generation according to Period Detection (autocorellation) * Sonagram, FFTView and Distortion-Dialog now use ScaleWidgets * New ScaleWidget gives the user more information * Improved ProgressDialog and Interpolation class to allow multiple threads * fixed some minor bugs 0.28 [1998-07-15] (by Martin Wilz ) * changes in curvewidget (recent point has another pixmap). * sorting of labels now works without overwriting of QGList::compareItems. * bug fix for saving selection. * save Block function added. * signal finding function in markers.cpp: gui improved. * some smaller bug fixes. 0.27 [1998-07-14] (by Martin Wilz ) * first release, but never uploaded, because ftp.kde.org was down. diff --git a/plugins/record/RecordPlugin.cpp b/plugins/record/RecordPlugin.cpp index 26b7cc6e..b8453753 100644 --- a/plugins/record/RecordPlugin.cpp +++ b/plugins/record/RecordPlugin.cpp @@ -1,1619 +1,1619 @@ /************************************************************************* RecordPlugin.cpp - plugin for recording audio data ------------------- begin : Wed Jul 09 2003 copyright : (C) 2003 by Thomas Eschenbacher email : Thomas.Eschenbacher@gmx.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "libkwave/Compression.h" #include "libkwave/FileInfo.h" #include "libkwave/InsertMode.h" #include "libkwave/MessageBox.h" #include "libkwave/PluginManager.h" #include "libkwave/Sample.h" #include "libkwave/SampleFIFO.h" #include "libkwave/SampleFormat.h" #include "libkwave/SignalManager.h" #include "libkwave/String.h" #include "libkwave/Utils.h" #include "libkwave/Writer.h" #include "Record-ALSA.h" #include "Record-OSS.h" #include "Record-PulseAudio.h" #include "Record-Qt.h" #include "RecordDevice.h" #include "RecordDialog.h" #include "RecordPlugin.h" #include "RecordThread.h" #include "SampleDecoderLinear.h" KWAVE_PLUGIN(record, RecordPlugin) #define OPEN_RETRY_TIME 1000 /**< time interval for trying to open [ms] */ //*************************************************************************** Kwave::RecordPlugin::RecordPlugin(QObject *parent, const QVariantList &args) :Kwave::Plugin(parent, args), m_method(Kwave::RECORD_NONE), m_device_name(), m_controller(), m_state(Kwave::REC_EMPTY), m_device(Q_NULLPTR), m_dialog(Q_NULLPTR), m_thread(Q_NULLPTR), m_decoder(Q_NULLPTR), m_prerecording_queue(), m_writers(Q_NULLPTR), m_buffers_recorded(0), m_inhibit_count(0), m_trigger_value(), m_retry_timer() { m_retry_timer.setSingleShot(true); connect(&m_retry_timer, SIGNAL(timeout()), this, SLOT(retryOpen()), Qt::QueuedConnection ); } //*************************************************************************** Kwave::RecordPlugin::~RecordPlugin() { Q_ASSERT(!m_dialog); if (m_dialog) delete m_dialog; m_dialog = Q_NULLPTR; Q_ASSERT(!m_thread); if (m_thread) delete m_thread; m_thread = Q_NULLPTR; Q_ASSERT(!m_decoder); if (m_decoder) delete m_decoder; m_decoder = Q_NULLPTR; if (m_device) delete m_device; m_device = Q_NULLPTR; } //*************************************************************************** QStringList *Kwave::RecordPlugin::setup(QStringList &previous_params) { Kwave::RecordDialog::Mode mode = Kwave::RecordDialog::SETTINGS_DEFAULT; qDebug("RecordPlugin::setup(%s)", DBG(previous_params.join(_(","))));; // if we have only one parameter, then we got called with a specific // mode, e.g. "show format settings only" if (previous_params.count() == 1) { const QString m = previous_params[0].toLower(); if (m == _("format")) mode = Kwave::RecordDialog::SETTINGS_FORMAT; else if (m == _("source")) mode = Kwave::RecordDialog::SETTINGS_SOURCE; else if (m == _("start_now")) mode = Kwave::RecordDialog::START_RECORDING; // get previous parameters for the setup dialog previous_params = manager().defaultParams(name()); qDebug("RecordPlugin::setup(%s) - MODE=%d", DBG(previous_params.join(_(","))), static_cast(mode)); } // create the setup dialog m_dialog = new(std::nothrow) Kwave::RecordDialog( parentWidget(), previous_params, &m_controller, mode ); Q_ASSERT(m_dialog); if (!m_dialog) return Q_NULLPTR; // create the lowlevel recording thread m_thread = new(std::nothrow) Kwave::RecordThread(); Q_ASSERT(m_thread); if (!m_thread) { delete m_dialog; m_dialog = Q_NULLPTR; return Q_NULLPTR; } // connect some signals of the setup dialog connect(m_dialog, SIGNAL(sigMethodChanged(Kwave::record_method_t)), this, SLOT(setMethod(Kwave::record_method_t))); connect(m_dialog, SIGNAL(sigDeviceChanged(QString)), this, SLOT(setDevice(QString))); connect(m_dialog, SIGNAL(sigTracksChanged(uint)), this, SLOT(changeTracks(uint))); connect(m_dialog, SIGNAL(sampleRateChanged(double)), this, SLOT(changeSampleRate(double))); connect(m_dialog, SIGNAL(sigCompressionChanged(Kwave::Compression::Type)), this, SLOT(changeCompression(Kwave::Compression::Type))); connect(m_dialog, SIGNAL(sigBitsPerSampleChanged(uint)), this, SLOT(changeBitsPerSample(uint))); connect(m_dialog, SIGNAL(sigSampleFormatChanged(Kwave::SampleFormat::Format)), this, SLOT(changeSampleFormat(Kwave::SampleFormat::Format))); connect(m_dialog, SIGNAL(sigBuffersChanged()), this, SLOT(buffersChanged())); connect(this, SIGNAL(sigRecordedSamples(sample_index_t)), m_dialog, SLOT(setRecordedSamples(sample_index_t))); connect(m_dialog, SIGNAL(sigTriggerChanged(bool)), &m_controller, SLOT(enableTrigger(bool))); m_controller.enableTrigger( m_dialog->params().record_trigger_enabled || m_dialog->params().start_time_enabled ); connect(m_dialog, SIGNAL(sigPreRecordingChanged(bool)), &m_controller, SLOT(enablePrerecording(bool))); connect(m_dialog, SIGNAL(sigPreRecordingChanged(bool)), this, SLOT(prerecordingChanged(bool))); m_controller.enablePrerecording(m_dialog->params().pre_record_enabled); // connect the record controller and this connect(&m_controller, SIGNAL(sigReset(bool&)), this, SLOT(resetRecording(bool&))); connect(&m_controller, SIGNAL(sigStartRecord()), this, SLOT(startRecording())); connect(&m_controller, SIGNAL(sigStopRecord(int)), &m_controller, SLOT(deviceRecordStopped(int))); connect(&m_controller, SIGNAL(stateChanged(Kwave::RecordState)), this, SLOT(stateChanged(Kwave::RecordState))); // connect record controller and record thread connect(m_thread, SIGNAL(stopped(int)), &m_controller, SLOT(deviceRecordStopped(int))); // connect us to the record thread connect(m_thread, SIGNAL(stopped(int)), this, SLOT(recordStopped(int))); connect(m_thread, SIGNAL(bufferFull()), this, SLOT(processBuffer()), Qt::QueuedConnection); // dummy init -> disable format settings m_dialog->setSupportedTracks(0, 0); // activate the recording method setMethod(m_dialog->params().method); // directly start recording if requested if (mode == Kwave::RecordDialog::START_RECORDING) m_controller.actionStart(); QStringList *list = new(std::nothrow) QStringList(); Q_ASSERT(list); if (list && (m_dialog->exec() == QDialog::Accepted)) { // user has pressed "OK" *list = m_dialog->params().toList(); } else { // user pressed "Cancel" if (list) delete list; list = Q_NULLPTR; } /* de-queue all buffers that are pending and remove the record thread */ if (m_thread) { m_thread->stop(); while (m_thread->queuedBuffers()) processBuffer(); delete m_thread; m_thread = Q_NULLPTR; } if (m_decoder) delete m_decoder; m_decoder = Q_NULLPTR; delete m_dialog; m_dialog = Q_NULLPTR; // flush away all prerecording buffers m_prerecording_queue.clear(); // enable undo again if we recorded something if (!signalManager().isEmpty()) signalManager().enableUndo(); return list; } //*************************************************************************** void Kwave::RecordPlugin::notice(QString message) { Q_ASSERT(m_dialog); if (m_dialog) m_dialog->message(message); } //*************************************************************************** void Kwave::RecordPlugin::closeDevice() { if (m_retry_timer.isActive()) m_retry_timer.stop(); if (m_device) { m_device->close(); delete m_device; m_device = Q_NULLPTR; } } //*************************************************************************** void Kwave::RecordPlugin::setMethod(Kwave::record_method_t method) { Q_ASSERT(m_dialog); if (!m_dialog) return; InhibitRecordGuard _lock(*this); // don't record while settings change qDebug("RecordPlugin::setMethod(%d)", static_cast(method)); // change the recording method (class RecordDevice) if ((method != m_method) || !m_device) { if (m_device) delete m_device; m_device = Q_NULLPTR; bool searching = false; // use the previous device QString section = _("plugin ") + name(); KConfigGroup cfg = KSharedConfig::openConfig()->group(section); // restore the previous device QString device = cfg.readEntry( _("last_device_%1").arg(static_cast(method))); // qDebug("<<< %d -> '%s'", static_cast(method), device.data()); m_device_name = device; do { switch (method) { #ifdef HAVE_OSS_SUPPORT case Kwave::RECORD_OSS: m_device = new(std::nothrow) Kwave::RecordOSS(); Q_ASSERT(m_device); break; #endif /* HAVE_OSS_SUPPORT */ #ifdef HAVE_ALSA_SUPPORT case Kwave::RECORD_ALSA: m_device = new(std::nothrow) Kwave::RecordALSA(); Q_ASSERT(m_device); break; #endif /* HAVE_ALSA_SUPPORT */ #ifdef HAVE_PULSEAUDIO_SUPPORT case Kwave::RECORD_PULSEAUDIO: m_device = new(std::nothrow) Kwave::RecordPulseAudio(); Q_ASSERT(m_device); break; #endif /* HAVE_PULSEAUDIO_SUPPORT */ #ifdef HAVE_QT_AUDIO_SUPPORT case Kwave::RECORD_QT: m_device = new(std::nothrow) Kwave::RecordQt(); Q_ASSERT(m_device); break; #endif /* HAVE_QT_AUDIO_SUPPORT */ default: qDebug("unsupported recording method (%d)", static_cast(method)); if (!searching) { // start trying all other methods searching = true; method = Kwave::RECORD_NONE; ++method; continue; } else { // try next method ++method; } qDebug("unsupported recording method - trying next (%d)", static_cast(method)); if (method != Kwave::RECORD_INVALID) continue; } break; } while (true); } Q_ASSERT(m_device); // if we found no recording method if (method == Kwave::RECORD_INVALID) { qWarning("found no valid recording method"); } // take the change in the method m_method = method; // activate the cange in the dialog m_dialog->setMethod(method); // set list of supported devices QStringList supported_devices; Q_ASSERT(m_device); if (m_device) supported_devices = m_device->supportedDevices(); m_dialog->setSupportedDevices(supported_devices); // set current device (again), no matter if supported or not, // the dialog will take care of this. setDevice(m_device_name); // check the filter for the "select..." dialog. If it is // empty, the "select" dialog will be disabled QString file_filter; if (m_device) file_filter = m_device->fileFilter(); m_dialog->setFileFilter(file_filter); } //*************************************************************************** void Kwave::RecordPlugin::retryOpen() { qDebug("RecordPlugin::retryOpen()"); setDevice(m_device_name); } //*************************************************************************** void Kwave::RecordPlugin::setDevice(const QString &device) { Q_ASSERT(m_dialog); Q_ASSERT(m_device); if (!m_dialog || !m_device) return; InhibitRecordGuard _lock(*this); // don't record while settings change qDebug("RecordPlugin::setDevice('%s')", DBG(device)); if (m_retry_timer.isActive()) m_retry_timer.stop(); // select the default device if this one is not supported QString dev = device; QStringList supported = m_device->supportedDevices(); if (!supported.isEmpty() && !supported.contains(device)) { // use the first entry as default dev = supported.first(); qDebug("RecordPlugin::setDevice(%s) -> fallback to '%s'", DBG(device), DBG(dev)); } // if there was no valid device name, fall back to default device if (dev.startsWith(_("#"))) { dev = _("/dev/dsp"); qDebug("RecordPlugin::setDevice(%s) -> no valid device, using '%s'", DBG(device), DBG(dev)); } // open and initialize the device QString result = m_device->open(dev); // set the device in the dialog m_device_name = dev; m_dialog->setDevice(dev); // remember the device selection, just for the GUI // for the next change in the method QString section = _("plugin ") + name(); KConfigGroup cfg = KSharedConfig::openConfig()->group(section); cfg.writeEntry(_("last_device_%1").arg( static_cast(m_method)), m_device_name); // qDebug(">>> %d -> '%s'", static_cast(m_method), DBG(m_device_name)); cfg.sync(); if (!result.isNull()) { bool shouldRetry = false; qWarning("RecordPlugin::setDevice('%s'): " "opening the device failed. error message='%s'", DBG(device), DBG(result)); m_controller.setInitialized(false); if (m_device_name.length()) { // build a short device name for showing to the user QString short_device_name = m_device_name; if (m_device_name.contains(_("|"))) { // tree syntax: extract card + device short_device_name = m_device_name.section(_("|"), 0, 0); if (m_device_name.section(_("|"), 3, 3).length()) short_device_name += _(", ") + m_device_name.section(_("|"), 3, 3); } bool errIsNumeric = false; int errNumber = result.toInt(&errIsNumeric); if (errIsNumeric) { if (errNumber == ENODEV) { result = i18n( "Maybe your system lacks support for the "\ "corresponding hardware or the hardware is not "\ "connected." ); } else if (errNumber == EBUSY) { result = i18n( "The audio device seems to be occupied by another "\ "application. Retrying..." ); shouldRetry = true; } else { result = i18n( "Some unexpected error happened (%1). "\ "You may try an other recording method or "\ "recording device.", QString::fromLocal8Bit(strerror(errNumber)) ); } } if (result.length()) { if (shouldRetry) { notice(result); } else { m_dialog->showDevicePage(); Kwave::MessageBox::sorry(parentWidget(), result, i18nc("%1 = a device name", "Unable to open the recording device (%1)", short_device_name)); } } } if (shouldRetry) { // retry later... m_retry_timer.start(OPEN_RETRY_TIME); } else { m_device_name = QString(); changeTracks(0); } } else { changeTracks(m_dialog->params().tracks); } if (paramsValid()) { m_controller.setInitialized(true); } else { qDebug("RecordPlugin::setDevice('%s') failed, " "returning to 'UNINITIALIZED'", DBG(device)); m_controller.setInitialized(false); } } //*************************************************************************** void Kwave::RecordPlugin::changeTracks(unsigned int new_tracks) { Q_ASSERT(m_dialog); if (!m_dialog) return; InhibitRecordGuard _lock(*this); // don't record while settings change // qDebug("RecordPlugin::changeTracks(%u)", new_tracks); if (!m_device || m_device_name.isNull()) { // no device -> dummy/shortcut m_dialog->setSupportedTracks(0, 0); m_dialog->setTracks(0); changeSampleRate(0); return; } // check the supported tracks unsigned int min = 0; unsigned int max = 0; if ((m_device->detectTracks(min, max) < 0) || (max < 1)) min = max = 0; if (min > max) min = max; unsigned int channels = new_tracks; if ((channels < min) || (channels > max)) { // clip to the supported number of tracks if (channels < min) channels = min; if (channels > max) channels = max; qDebug("RecordPlugin::changeTracks(%u) -> clipped to %u", new_tracks, channels); if ((new_tracks && channels) && (new_tracks != channels)) { QString s1; switch (new_tracks) { case 1: s1 = i18n("Mono"); break; case 2: s1 = i18n("Stereo"); break; case 4: s1 = i18n("Quadro"); break; default: s1 = i18n("%1 channels", new_tracks); } QString s2; switch (channels) { case 1: s2 = i18n("Mono"); break; case 2: s2 = i18n("Stereo"); break; case 4: s2 = i18n("Quadro"); break; default: s2 = i18n("%1 channels", channels); } notice(i18n("%1 is not supported, using %2", s1, s2)); } } Q_ASSERT(channels >= min); Q_ASSERT(channels <= max); m_dialog->setSupportedTracks(min, max); // try to activate the new number of tracks int err = m_device->setTracks(channels); if (err < 0) { // revert to the current device setting if failed int t = m_device->tracks(); if (t > 0) { // current device state seems to be valid channels = t; if (channels < min) channels = min; if (channels > max) channels = max; } else { // current device state is invalid channels = 0; } if (new_tracks && (channels > 0)) notice( i18n("Recording with %1 channel(s) failed, "\ "using %2 channel(s)", new_tracks, channels)); } m_dialog->setTracks(channels); // activate the new sample rate changeSampleRate(m_dialog->params().sample_rate); } //*************************************************************************** void Kwave::RecordPlugin::changeSampleRate(double new_rate) { Q_ASSERT(m_dialog); if (!m_dialog) return; InhibitRecordGuard _lock(*this); // don't record while settings change // qDebug("RecordPlugin::changeSampleRate(%u)", Kwave::toInt(new_rate)); if (!m_device || m_device_name.isNull()) { // no device -> dummy/shortcut m_dialog->setSampleRate(0); changeCompression(Kwave::Compression::INVALID); return; } // check the supported sample rates QList supported_rates = m_device->detectSampleRates(); bool is_supported = false; foreach (const double &r, supported_rates) if (qFuzzyCompare(new_rate, r)) { is_supported = true; break; } double rate = new_rate; if (!is_supported && !supported_rates.isEmpty()) { // find the nearest sample rate double nearest = supported_rates.last(); foreach (double r, supported_rates) { if (fabs(r - rate) <= fabs(nearest - rate)) nearest = r; } rate = nearest; const QString sr1(m_dialog->rate2string(new_rate)); const QString sr2(m_dialog->rate2string(rate)); if ((Kwave::toInt(new_rate) > 0) && (Kwave::toInt(rate) > 0) && (Kwave::toInt(new_rate) != Kwave::toInt(rate))) notice(i18n("%1 Hz is not supported, "\ "using %2 Hz", sr1, sr2)); } m_dialog->setSupportedSampleRates(supported_rates); // try to activate the new sample rate int err = m_device->setSampleRate(rate); if (err < 0) { // revert to the current device setting if failed rate = m_device->sampleRate(); if (rate < 0) rate = 0; const QString sr1(m_dialog->rate2string(new_rate)); const QString sr2(m_dialog->rate2string(rate)); if ((Kwave::toInt(new_rate) > 0) && (Kwave::toInt(rate) > 0) && (Kwave::toInt(new_rate) != Kwave::toInt(rate))) notice(i18n("%1 Hz failed, using %2 Hz", sr1, sr2)); } m_dialog->setSampleRate(rate); // set the compression again changeCompression(m_dialog->params().compression); } //*************************************************************************** void Kwave::RecordPlugin::changeCompression( Kwave::Compression::Type new_compression ) { Q_ASSERT(m_dialog); if (!m_dialog) return; InhibitRecordGuard _lock(*this); // don't record while settings change // qDebug("RecordPlugin::changeCompression(%d)", new_compression); if (!m_device || m_device_name.isNull()) { // no device -> dummy/shortcut m_dialog->setCompression(-1); changeBitsPerSample(0); return; } // check the supported compressions QList supported_comps = m_device->detectCompressions(); Kwave::Compression::Type compression = new_compression; if (!supported_comps.contains(compression) && (compression != Kwave::Compression::NONE)) { // try to disable the compression (type 0) compression = Kwave::Compression::NONE; if (!supported_comps.isEmpty() && !supported_comps.contains(compression)) { // what now, "None" is not supported // -> take the first supported one compression = supported_comps[0]; } if (compression != new_compression) { const QString c1(Kwave::Compression(new_compression).name()); const QString c2(Kwave::Compression(compression).name()); notice(i18n("Compression '%1' not supported, using '%2'", c1, c2)); } } m_dialog->setSupportedCompressions(supported_comps); // try to activate the new compression int err = m_device->setCompression(compression); if (err < 0) { // revert to the current device setting if failed if (compression != m_device->compression()) { const QString c1(Kwave::Compression(compression).name()); const QString c2(Kwave::Compression(m_device->compression()).name()); notice(i18n("Compression '%1' failed, using '%2'.", c1 ,c2)); } compression = m_device->compression(); } m_dialog->setCompression(compression); // set the resolution in bits per sample again changeBitsPerSample(m_dialog->params().bits_per_sample); } //*************************************************************************** void Kwave::RecordPlugin::changeBitsPerSample(unsigned int new_bits) { Q_ASSERT(m_dialog); if (!m_dialog) return; InhibitRecordGuard _lock(*this); // don't record while settings change // qDebug("RecordPlugin::changeBitsPerSample(%d)", new_bits); if (!m_device || m_device_name.isNull()) { // no device -> dummy/shortcut m_dialog->setBitsPerSample(0); changeSampleFormat(Kwave::SampleFormat::Unknown); return; } // check the supported resolution in bits per sample QList supported_bits = m_device->supportedBits(); int bits = new_bits; if (!supported_bits.contains(bits) && !supported_bits.isEmpty()) { // find the nearest resolution int nearest = supported_bits.last(); foreach (unsigned int b, supported_bits) { if (qAbs(Kwave::toInt(b) - nearest) <= qAbs(bits - nearest)) nearest = Kwave::toInt(b); } bits = nearest; if ((Kwave::toInt(new_bits) > 0) && (bits > 0)) notice( i18n("%1 bits per sample is not supported, "\ "using %2 bits per sample", Kwave::toInt(new_bits), bits)); } m_dialog->setSupportedBits(supported_bits); // try to activate the resolution int err = m_device->setBitsPerSample(bits); if (err < 0) { // revert to the current device setting if failed bits = m_device->bitsPerSample(); if (bits < 0) bits = 0; if ((new_bits > 0) && (bits > 0)) notice( i18n("%1 bits per sample failed, " "using %2 bits per sample", Kwave::toInt(new_bits), bits)); } m_dialog->setBitsPerSample(bits); // set the sample format again changeSampleFormat(m_dialog->params().sample_format); } //*************************************************************************** void Kwave::RecordPlugin::changeSampleFormat( Kwave::SampleFormat::Format new_format) { Q_ASSERT(m_dialog); if (!m_dialog) return; InhibitRecordGuard _lock(*this); // don't record while settings change if (!m_device || m_device_name.isNull()) { // no device -> dummy/shortcut m_dialog->setSampleFormat(Kwave::SampleFormat::Unknown); return; } // check the supported sample formats QList supported_formats = m_device->detectSampleFormats(); Kwave::SampleFormat::Format format = new_format; if (!supported_formats.contains(format) && !supported_formats.isEmpty()) { // use the device default instead format = m_device->sampleFormat(); // if this was also not supported -> stupid device !? if (!supported_formats.contains(format)) { format = supported_formats.first(); // just take the first one :-o } Kwave::SampleFormat::Map sf; const QString s1 = sf.description(sf.findFromData(new_format), true); const QString s2 = sf.description(sf.findFromData(format), true); if (!(new_format == -1) && !(new_format == format)) { notice(i18n("Sample format '%1' is not supported, "\ "using '%2'", s1, s2)); } } m_dialog->setSupportedSampleFormats(supported_formats); // try to activate the new format int err = m_device->setSampleFormat(format); if (err < 0) { // use the device default instead format = m_device->sampleFormat(); Kwave::SampleFormat::Map sf; const QString s1 = sf.description(sf.findFromData(new_format), true); const QString s2 = sf.description(sf.findFromData(format), true); if (format > 0) notice( i18n("Sample format '%1' failed, using '%2'", s1, s2)); } m_dialog->setSampleFormat(format); } //*************************************************************************** void Kwave::RecordPlugin::buffersChanged() { InhibitRecordGuard _lock(*this); // don't record while settings change // this implicitly activates the new settings } //*************************************************************************** void Kwave::RecordPlugin::enterInhibit() { m_inhibit_count++; if ((m_inhibit_count == 1) && m_thread) { // set hourglass cursor QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); // qDebug("RecordPlugin::enterInhibit() - STOPPING"); m_thread->stop(); Q_ASSERT(!m_thread->isRunning()); // de-queue all buffers that are still in the queue while (m_thread->queuedBuffers()) processBuffer(); } } //*************************************************************************** void Kwave::RecordPlugin::leaveInhibit() { Q_ASSERT(m_inhibit_count); Q_ASSERT(m_dialog); if (m_inhibit_count) m_inhibit_count--; while (!m_inhibit_count && paramsValid()) { // qDebug("RecordPlugin::leaveInhibit() - STARTING (" // "%d channels, %d bits)", // m_dialog->params().tracks, // m_dialog->params().bits_per_sample); Q_ASSERT(!m_thread->isRunning()); if (m_thread->isRunning()) break; // set new parameters for the recorder setupRecordThread(); // and let the thread run (again) m_thread->start(); break; } // take back the hourglass cursor if (!m_inhibit_count) QApplication::restoreOverrideCursor(); } //*************************************************************************** bool Kwave::RecordPlugin::paramsValid() { if (!m_thread || !m_device || !m_dialog) return false; // check for a valid/usable record device if (m_device_name.isNull()) return false; if ( (m_device->sampleFormat() != Kwave::SampleFormat::Unsigned) && (m_device->sampleFormat() != Kwave::SampleFormat::Signed) ) return false; if (m_device->bitsPerSample() < 1) return false; if (m_device->endianness() == Kwave::UnknownEndian) return false; // check for valid parameters in the dialog const Kwave::RecordParams ¶ms = m_dialog->params(); if (params.tracks < 1) return false; if ( (params.sample_format != Kwave::SampleFormat::Unsigned) && (params.sample_format != Kwave::SampleFormat::Signed) ) return false; return true; } //*************************************************************************** void Kwave::RecordPlugin::resetRecording(bool &accepted) { InhibitRecordGuard _lock(*this); if (m_writers) m_writers->clear(); emitCommand(_("nomacro:close()")); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); accepted = manager().signalManager().isEmpty(); if (!accepted) return; // the parent context might have changed, maybe we have to // re-parent this plugin instance! migrateToActiveContext(); m_buffers_recorded = 0; m_controller.setEmpty(true); emit sigRecordedSamples(0); } //*************************************************************************** void Kwave::RecordPlugin::setupRecordThread() { Q_ASSERT(m_thread); Q_ASSERT(m_dialog); Q_ASSERT(m_device); if (!paramsValid()) return; // stop the thread if necessary (should never happen) Q_ASSERT(!m_thread->isRunning()); if (m_thread->isRunning()) m_thread->stop(); Q_ASSERT(!m_thread->isRunning()); // delete the previous decoder if (m_decoder) delete m_decoder; m_decoder = Q_NULLPTR; // our own reference to the record parameters const Kwave::RecordParams ¶ms = m_dialog->params(); if (!paramsValid()) return; // create a decoder for the current sample format switch (params.compression) { case Kwave::Compression::NONE: switch (params.sample_format) { case Kwave::SampleFormat::Unsigned: /* FALLTHROUGH */ case Kwave::SampleFormat::Signed: // decoder for all linear formats m_decoder = new(std::nothrow) Kwave::SampleDecoderLinear( m_device->sampleFormat(), m_device->bitsPerSample(), m_device->endianness() ); break; default: notice( i18n("The current sample format is not supported!") ); } break; default: notice( i18n("The current compression type is not supported!") ); return; } Q_ASSERT(m_decoder); if (!m_decoder) { Kwave::MessageBox::sorry(m_dialog, i18n("Out of memory")); return; } // set up the prerecording queues m_prerecording_queue.clear(); if (params.pre_record_enabled) { // prepare a queue for each track const unsigned int prerecording_samples = Kwave::toUint( rint(params.pre_record_time * params.sample_rate)); m_prerecording_queue.resize(params.tracks); for (int i=0; i < m_prerecording_queue.size(); i++) m_prerecording_queue[i].setSize(prerecording_samples); if (m_prerecording_queue.size() != Kwave::toInt(params.tracks)) { m_prerecording_queue.clear(); Kwave::MessageBox::sorry(m_dialog, i18n("Out of memory")); return; } } // set up the recording trigger values m_trigger_value.resize(params.tracks); m_trigger_value.fill(0.0); // set up the record thread m_thread->setRecordDevice(m_device); unsigned int buf_count = params.buffer_count; unsigned int buf_size = params.tracks * m_decoder->rawBytesPerSample() * (1 << params.buffer_size); m_thread->setBuffers(buf_count, buf_size); } //*************************************************************************** void Kwave::RecordPlugin::startRecording() { Q_ASSERT(m_dialog); Q_ASSERT(m_thread); Q_ASSERT(m_device); if (!m_dialog || !m_thread || !m_device) return; InhibitRecordGuard _lock(*this); // don't record while settings change if ((m_state != Kwave::REC_PAUSED) || !m_decoder) { double rate = m_dialog->params().sample_rate; unsigned int tracks = m_dialog->params().tracks; unsigned int bits = m_dialog->params().bits_per_sample; if (!tracks) return; /* * if tracks or sample rate has changed * -> start over with a new signal and new settings */ if ((!m_writers) || (m_writers->tracks() != tracks) || !qFuzzyCompare( Kwave::FileInfo(signalManager().metaData()).rate(), rate)) { // create a new and empty signal emitCommand(QString(_("newsignal(0,%1,%2,%3)")).arg( rate).arg(bits).arg(tracks)); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); // the parent context might have changed, maybe we have to // re-parent this plugin instance! migrateToActiveContext(); Kwave::SignalManager &mgr = signalManager(); if (!qFuzzyCompare(mgr.rate(), rate) || (mgr.bits() != bits) || (mgr.tracks() != tracks)) { emitCommand(_("close")); return; } // we do not need undo while recording, this would only waste undo // buffers with modified/inserted data signalManager().disableUndo(); // create a sink for our audio data if (m_writers) delete m_writers; m_writers = new(std::nothrow) Kwave::MultiTrackWriter( signalManager(), Kwave::Append); if ((!m_writers) || (m_writers->tracks() != tracks)) { Kwave::MessageBox::sorry(m_dialog, i18n("Out of memory")); return; } } else { // re-use the current signal and append to it } // initialize the file information Kwave::FileInfo fileInfo(signalManager().metaData()); fileInfo.setRate(rate); fileInfo.setBits(bits); fileInfo.setTracks(tracks); fileInfo.set(Kwave::INF_MIMETYPE, _("audio/vnd.wave")); fileInfo.set(Kwave::INF_SAMPLE_FORMAT, Kwave::SampleFormat(m_dialog->params().sample_format).toInt()); fileInfo.set(Kwave::INF_COMPRESSION, m_dialog->params().compression); // add our Kwave Software tag const KAboutData about_data = KAboutData::applicationData(); QString software = about_data.componentName() + _("-") + about_data.version() + _(" ") + i18n("(built with KDE Frameworks %1)", _(KXMLGUI_VERSION_STRING)); fileInfo.set(Kwave::INF_SOFTWARE, software); // add a date tag, ISO format QDate now(QDate::currentDate()); QString date; date = date.sprintf("%04d-%02d-%02d", now.year(), now.month(), now.day()); fileInfo.set(Kwave::INF_CREATION_DATE, date); signalManager().setFileInfo(fileInfo, false); } // now the recording can be considered to be started m_controller.deviceRecordStarted(); } //*************************************************************************** void Kwave::RecordPlugin::recordStopped(int reason) { qDebug("RecordPlugin::recordStopped(%d)", reason); if (reason >= 0) return; // nothing to do // recording was aborted QString err_msg; switch (reason) { case -ENOBUFS: err_msg = i18n("Buffer overrun. Please increase the "\ "number and/or size of the record buffers."); break; case -EBUSY: err_msg = i18n("The recording device seems to be busy."); break; default: err_msg = i18n("Reading from the recording device failed. "\ "Error number = %1 (%2)", -reason, QString::fromLocal8Bit(strerror(-reason))); } Kwave::MessageBox::error(m_dialog, err_msg); if (m_writers) m_writers->flush(); qDebug("RecordPlugin::recordStopped(): last=%lu", static_cast( (m_writers) ? m_writers->last() : 0)); // flush away all prerecording buffers m_prerecording_queue.clear(); // update the file info if we recorded something // NOTE: this implicitly sets the "modified" flag of the signal if (m_writers && m_writers->last()) { Kwave::FileInfo info(signalManager().metaData()); info.setLength(signalLength()); info.setTracks(m_dialog->params().tracks); signalManager().setFileInfo(info, false); } } //*************************************************************************** void Kwave::RecordPlugin::stateChanged(Kwave::RecordState state) { m_state = state; switch (m_state) { case Kwave::REC_UNINITIALIZED: case Kwave::REC_EMPTY: case Kwave::REC_PAUSED: case Kwave::REC_DONE: // reset buffer status if (m_writers) { m_writers->flush(); delete m_writers; m_writers = Q_NULLPTR; } m_buffers_recorded = 0; m_dialog->updateBufferState(0, 0); break; default: ; } } //*************************************************************************** void Kwave::RecordPlugin::updateBufferProgressBar() { Q_ASSERT(m_dialog); Q_ASSERT(m_thread); if (!m_dialog || !m_thread) return; unsigned int buffers_total = m_dialog->params().buffer_count; // if we are still recording: update the progress bar if ((m_state != Kwave::REC_EMPTY) && (m_state != Kwave::REC_PAUSED) && (m_state != Kwave::REC_DONE)) { // count up the number of recorded buffers m_buffers_recorded++; if (m_buffers_recorded <= buffers_total) { // buffers are just in progress of getting filled m_dialog->updateBufferState(m_buffers_recorded, buffers_total); } else { // we have remaining+1 buffers (one is currently filled) unsigned int remaining = m_thread->remainingBuffers() + 1; if (remaining > buffers_total) remaining = buffers_total; m_dialog->updateBufferState(remaining, buffers_total); } } else { // no longer recording: count the buffer downwards unsigned int queued = m_thread->queuedBuffers(); if (!queued) buffers_total = 0; m_dialog->updateBufferState(queued, buffers_total); } } //*************************************************************************** void Kwave::RecordPlugin::split(QByteArray &raw_data, QByteArray &dest, unsigned int bytes_per_sample, unsigned int track, unsigned int tracks) { unsigned int samples = raw_data.size() / bytes_per_sample / tracks; #if 0 // simple sawtooth generator, based on raw data // works for up to 16 channels static int saw[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; raw_data.fill(0x05); for (unsigned int s = 0; s < samples; s++) { int v = saw[track]; for (unsigned int byte = 0; byte < bytes_per_sample; byte++) { quint8 x = (quint8)v; raw_data[(((s * tracks) + track) * bytes_per_sample) + byte] = x; v >>= 8; } const int max = (1 << ((bytes_per_sample * 8) - 1)) - 1; saw[track] += max / 64; if (saw[track] >= max) saw[track] = 0; } #endif if (tracks == 1) { // this would give a 1:1 memcpy dest = raw_data; } else { switch (bytes_per_sample) { case 1: { // 1...8 bits per sample, use 8 bit pointers const quint8 *src = reinterpret_cast(raw_data.constData()); quint8 *dst = reinterpret_cast(dest.data()); src += track; while (samples) { *dst = *src; dst++; src += tracks; samples--; } break; } case 2: { // 9...16 bits per sample, use 16 bit pointers const quint16 *src = reinterpret_cast(raw_data.constData()); quint16 *dst = reinterpret_cast(dest.data()); src += track; while (samples) { *dst = *src; dst++; src += tracks; samples--; } break; } case 3: { // 17...24 bits per sample, use 8 bit pointers, three times const quint8 *src = reinterpret_cast(raw_data.constData()); quint8 *dst = reinterpret_cast(dest.data()); src += track * 3; while (samples) { *(dst++) = *(src++); *(dst++) = *(src++); *(dst++) = *(src++); src += (tracks - 1) * 3; samples--; } break; } case 4: { // 24...32 bits per sample, use 32 bit pointers const quint32 *src = reinterpret_cast(raw_data.constData()); quint32 *dst = reinterpret_cast(dest.data()); src += track; while (samples) { *dst = *src; dst++; src += tracks; samples--; } break; } case 8: { // 64 bits per sample, use 64 bit pointers const quint64 *src = reinterpret_cast(raw_data.constData()); quint64 *dst = reinterpret_cast(dest.data()); src += track; while (samples) { *dst = *src; dst++; src += tracks; samples--; } break; } default: { // default: byte wise operation const quint8 *src = reinterpret_cast(raw_data.constData()); quint8 *dst = reinterpret_cast(dest.data()); src += (track * bytes_per_sample); unsigned int increment = (tracks - 1) * bytes_per_sample; while (samples) { for (unsigned int b = 0; b < bytes_per_sample; b++) { *dst = *src; dst++; src++; samples--; } src += increment; } } } } } //*************************************************************************** bool Kwave::RecordPlugin::checkTrigger(unsigned int track, const Kwave::SampleArray &buffer) { Q_ASSERT(m_dialog); if (!m_dialog) return false; // check if the recording start time has been reached if (m_dialog->params().start_time_enabled) { if (QDateTime::currentDateTime() < m_dialog->params().start_time) return false; } // shortcut if no trigger has been set if (!m_dialog->params().record_trigger_enabled) return true; // check the input parameters if (!buffer.size()) return false; if (!m_writers) return false; if (m_trigger_value.size() != Kwave::toInt(m_writers->tracks())) return false; // pass the buffer through a rectifier and a lowpass with // center frequency about 2Hz to get the amplitude float trigger = static_cast( m_dialog->params().record_trigger / 100.0); const float rate = static_cast( m_dialog->params().sample_rate); /* * simple lowpass calculation: * * 1 + z * H(z) = a0 * ----------- | z = e ^ (j*2*pi*f) * z + b1 * * 1 1 - n * a0 = ----- b1 = -------- * 1 + n 1 + n * * Fg = fg / fa * * n = cot(Pi * Fg) * * y[t] = a0 * x[t] + a1 * x[t-1] - b1 * y[t-1] * */ // rise coefficient: ~20Hz const float f_rise = 20.0f; float Fg = f_rise / rate; float n = 1.0f / tanf(float(M_PI) * Fg); const float a0_r = 1.0f / (1.0f + n); const float b1_r = (1.0f - n) / (1.0f + n); // fall coefficient: ~1.0Hz const float f_fall = 1.0f; Fg = f_fall / rate; n = 1.0f / tanf(float(M_PI) * Fg); const float a0_f = 1.0f / (1.0f + n); const float b1_f = (1.0f - n) / (1.0f + n); float y = m_trigger_value[track]; float last_x = y; for (unsigned int t = 0; t < buffer.size(); ++t) { float x = fabsf(sample2float(buffer[t])); /* rectifier */ if (x > y) { /* diode */ // rise if amplitude is above average (serial R) y = (a0_r * x) + (a0_r * last_x) - (b1_r * y); } // fall (parallel R) y = (a0_f * x) + (a0_f * last_x) - (b1_f * y); // remember x[t-1] last_x = x; // nice for debugging: // buffer[t] = (int)((double)(1 << (SAMPLE_BITS-1)) * y); if (y > trigger) return true; } m_trigger_value[track] = y; qDebug(">> level=%5.3g, trigger=%5.3g", y, trigger); return false; } //*************************************************************************** void Kwave::RecordPlugin::enqueuePrerecording(unsigned int track, const Kwave::SampleArray &decoded) { Q_ASSERT(m_dialog); Q_ASSERT(Kwave::toInt(track) < m_prerecording_queue.size()); if (!m_dialog) return; if (Kwave::toInt(track) >= m_prerecording_queue.size()) return; // append the array with decoded sample to the prerecording buffer m_prerecording_queue[track].put(decoded); } //*************************************************************************** void Kwave::RecordPlugin::flushPrerecordingQueue() { if (!m_prerecording_queue.size()) return; Q_ASSERT(m_dialog); Q_ASSERT(m_thread); Q_ASSERT(m_decoder); if (!m_dialog || !m_thread || !m_decoder) return; const Kwave::RecordParams ¶ms = m_dialog->params(); const unsigned int tracks = params.tracks; Q_ASSERT(tracks); if (!tracks) return; Q_ASSERT(m_writers); if (!m_writers) return; Q_ASSERT(tracks == m_writers->tracks()); if (!tracks || (tracks != m_writers->tracks())) return; for (unsigned int track=0; track < tracks; ++track) { Kwave::SampleFIFO &fifo = m_prerecording_queue[track]; Q_ASSERT(fifo.length()); if (!fifo.length()) continue; fifo.crop(); // enforce the correct size // push all buffers to the writer, starting at the tail Kwave::Writer *writer = (*m_writers)[track]; Q_ASSERT(writer); if (writer) { Kwave::SampleArray buffer(writer->blockSize()); unsigned int rest = fifo.length(); while (rest) { unsigned int read = fifo.get(buffer); if (read < 1) break; writer->write(buffer, read); rest -= read; } } else { // fallback: discard the FIFO content fifo.flush(); } Q_ASSERT(fifo.length() == 0); } // the queues are no longer needed m_prerecording_queue.clear(); // we have transferred data to the writers, we are no longer empty m_controller.setEmpty(false); } //*************************************************************************** void Kwave::RecordPlugin::processBuffer() { bool recording_done = false; // de-queue the buffer from the thread if (!m_thread) return; if (!m_thread->queuedBuffers()) return; QByteArray buffer = m_thread->dequeue(); // abort here if we have no dialog or no decoder if (!m_dialog || !m_decoder) return; // we received a buffer -> update the progress bar updateBufferProgressBar(); const Kwave::RecordParams ¶ms = m_dialog->params(); const unsigned int tracks = params.tracks; Q_ASSERT(tracks); if (!tracks) return; const unsigned int bytes_per_sample = m_decoder->rawBytesPerSample(); Q_ASSERT(bytes_per_sample); if (!bytes_per_sample) return; unsigned int samples = (buffer.size() / bytes_per_sample) / tracks; Q_ASSERT(samples); if (!samples) return; // check for reached recording time limit if enabled if (params.record_time_limited && m_writers) { const sample_index_t last = m_writers->last(); const sample_index_t already_recorded = (last) ? (last + 1) : 0; const sample_index_t limit = static_cast(rint( params.record_time * params.sample_rate)); if (already_recorded + samples >= limit) { // reached end of recording time, we are full if (m_state == Kwave::REC_RECORDING) { samples = Kwave::toUint( (limit > already_recorded) ? (limit - already_recorded) : 0); buffer.resize(samples * tracks * bytes_per_sample); } recording_done = true; } } QByteArray buf; buf.resize(bytes_per_sample * samples); Q_ASSERT(buf.size() == Kwave::toInt(bytes_per_sample * samples)); if (buf.size() != Kwave::toInt(bytes_per_sample * samples)) return; Kwave::SampleArray decoded(samples); Q_ASSERT(decoded.size() == samples); if (decoded.size() != samples) return; // check for trigger // note: this might change the state, which affects the // processing of all tracks ! if ((m_state == Kwave::REC_WAITING_FOR_TRIGGER) || ((m_state == Kwave::REC_PRERECORDING) && params.record_trigger_enabled) || ((m_state == Kwave::REC_PRERECORDING) && params.start_time_enabled)) { for (unsigned int track=0; track < tracks; ++track) { // split off and decode buffer with current track split(buffer, buf, bytes_per_sample, track, tracks); m_decoder->decode(buf, decoded); if (checkTrigger(track, decoded)) { m_controller.deviceTriggerReached(); break; } } } if ((m_state == Kwave::REC_RECORDING) && !m_prerecording_queue.isEmpty()) { // flush all prerecorded buffers to the output flushPrerecordingQueue(); } // use a copy of the state, in case it changes below ;-) Kwave::RecordState state = m_state; - for (unsigned int track=0; track < tracks; ++track) { + for (unsigned int track = 0; track < tracks; ++track) { // decode and care for all special effects, meters and so on // split off and decode buffer with current track split(buffer, buf, bytes_per_sample, track, tracks); m_decoder->decode(buf, decoded); // update the level meter and other effects m_dialog->updateEffects(track, decoded); // if the first buffer is full -> leave REC_BUFFERING // limit state transitions to a point before the first track is // processed (avoid asymmetry) if ((track == 0) && (m_state == Kwave::REC_BUFFERING) && (m_buffers_recorded > 1)) { m_controller.deviceBufferFull(); state = m_state; // might have changed! } switch (state) { case Kwave::REC_UNINITIALIZED: case Kwave::REC_EMPTY: case Kwave::REC_PAUSED: case Kwave::REC_DONE: case Kwave::REC_BUFFERING: case Kwave::REC_WAITING_FOR_TRIGGER: // already handled before or nothing to do... break; case Kwave::REC_PRERECORDING: // enqueue the buffers into a FIFO enqueuePrerecording(track, decoded); break; case Kwave::REC_RECORDING: { // put the decoded track data into the buffer if (!m_writers) break; // (could happen due to queued signal) Q_ASSERT(tracks == m_writers->tracks()); if (!tracks || (tracks != m_writers->tracks())) break; Kwave::Writer *writer = (*m_writers)[track]; Q_ASSERT(writer); if (writer) (*writer) << decoded; m_controller.setEmpty(false); break; } } } // update the number of recorded samples if (m_writers) emit sigRecordedSamples(m_writers->last() + 1); // if this was the last received buffer, change state if (recording_done && (m_state != Kwave::REC_DONE) && (m_state != Kwave::REC_EMPTY)) { m_controller.actionStop(); } } //*************************************************************************** void Kwave::RecordPlugin::prerecordingChanged(bool enable) { (void)enable; InhibitRecordGuard _lock(*this); // activate the change } //*************************************************************************** #include "RecordPlugin.moc" //*************************************************************************** //*************************************************************************** diff --git a/plugins/record/RecordThread.cpp b/plugins/record/RecordThread.cpp index 4000d575..aa4e4312 100644 --- a/plugins/record/RecordThread.cpp +++ b/plugins/record/RecordThread.cpp @@ -1,184 +1,210 @@ /************************************************************************* RecordThread.cpp - thread for lowlevel audio recording ------------------- begin : Mon Oct 20 2003 copyright : (C) 2003 by Thomas Eschenbacher email : Thomas.Eschenbacher@gmx.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "config.h" #include +#include #include #include "RecordDevice.h" #include "RecordThread.h" //*************************************************************************** Kwave::RecordThread::RecordThread() - :Kwave::WorkerThread(Q_NULLPTR, QVariant()), m_device(Q_NULLPTR), - m_empty_queue(), m_buffer_count(0), m_buffer_size(0) + :Kwave::WorkerThread(Q_NULLPTR, QVariant()), + m_lock(QMutex::Recursive), + m_device(Q_NULLPTR), + m_empty_queue(), + m_full_queue(), + m_buffer_count(0), + m_buffer_size(0) { } //*************************************************************************** Kwave::RecordThread::~RecordThread() { stop(); - m_full_queue.clear(); - m_empty_queue.clear(); + + { + QMutexLocker lock(&m_lock); + m_full_queue.clear(); + m_empty_queue.clear(); + } } //*************************************************************************** void Kwave::RecordThread::setRecordDevice(Kwave::RecordDevice *device) { Q_ASSERT(!isRunning()); if (isRunning()) return; m_device = device; } //*************************************************************************** int Kwave::RecordThread::setBuffers(unsigned int count, unsigned int size) { + QMutexLocker lock(&m_lock); + Q_ASSERT(!isRunning()); if (isRunning()) return -EBUSY; // flush all queues m_full_queue.clear(); m_empty_queue.clear(); // fill the "empty" queue again QByteArray buf(size, 0x00); for (unsigned int i = 0; i < count; i++) m_empty_queue.enqueue(buf); // take the new settings m_buffer_size = size; m_buffer_count = count; // return number of buffers or -ENOMEM if not even two allocated return (m_empty_queue.count() >= 2) ? m_empty_queue.count() : -ENOMEM; } //*************************************************************************** unsigned int Kwave::RecordThread::remainingBuffers() { + QMutexLocker lock(&m_lock); return (m_empty_queue.count()); } //*************************************************************************** unsigned int Kwave::RecordThread::queuedBuffers() { + QMutexLocker lock(&m_lock); return (m_full_queue.count()); } //*************************************************************************** QByteArray Kwave::RecordThread::dequeue() { + QMutexLocker lock(&m_lock); + if (m_full_queue.count()) { // de-queue the buffer from the full list QByteArray buf = m_full_queue.dequeue(); // put the buffer back to the empty list m_empty_queue.enqueue(buf); // return the buffer return buf; } else { // return an empty buffer return QByteArray(); } } //*************************************************************************** void Kwave::RecordThread::run() { - int result = 0; + int result = 0; bool interrupted = false; // read data until we receive a close signal while (!shouldStop() && !interrupted) { // dequeue a buffer from the "empty" queue - if (m_empty_queue.isEmpty()) { - // we had a "buffer overflow" - qWarning("RecordThread::run() -> NO EMPTY BUFFER FOUND !!!"); - result = -ENOBUFS; - break; - } + QByteArray buffer; + int len; + { + QMutexLocker lock(&m_lock); - QByteArray buffer = m_empty_queue.dequeue(); - int len = buffer.size(); - Q_ASSERT(buffer.size()); - if (!len) { - result = -ENOBUFS; - break; + if (m_empty_queue.isEmpty()) { + // we had a "buffer overflow" + qWarning("RecordThread::run() -> NO EMPTY BUFFER FOUND !!!"); + result = -ENOBUFS; + break; + } + + buffer = m_empty_queue.dequeue(); + len = buffer.size(); + Q_ASSERT(buffer.size()); + if (!len) { + result = -ENOBUFS; + break; + } } // read into the current buffer unsigned int offset = 0; while (len && !interrupted && !shouldStop()) { // read raw data from the record device result = (m_device) ? m_device->read(buffer, offset) : -EBADF; if ((result < 0) && (result != -EAGAIN)) qWarning("RecordThread: read result = %d (%s)", result, strerror(-result)); if (result == -EAGAIN) { continue; } else if (result == -EBADF) { // file open has failed interrupted = true; break; } else if (result == -EINTR) { // thread was interrupted, received signal? interrupted = true; break; } else if (result < 1) { // something went wrong !? interrupted = true; qWarning("RecordThread::run(): read returned %d", result); break; } else { offset += result; len = buffer.size() - offset; Q_ASSERT(len >= 0); if (len < 0) len = 0; } } // return buffer into the empty queue and abort on errors // do not use it if (interrupted && (result < 0)) { + QMutexLocker lock(&m_lock); m_empty_queue.enqueue(buffer); break; } // inform the application that there is something to dequeue - m_full_queue.enqueue(buffer); + { + QMutexLocker lock(&m_lock); + m_full_queue.enqueue(buffer); + } emit bufferFull(); } // do not evaluate the result of the last operation if there // was the external request to stop if (shouldStop() || (interrupted && (result > 0))) result = 0; if (result) emit stopped(result); } //*************************************************************************** //*************************************************************************** diff --git a/plugins/record/RecordThread.h b/plugins/record/RecordThread.h index 9f737a43..f05d8cca 100644 --- a/plugins/record/RecordThread.h +++ b/plugins/record/RecordThread.h @@ -1,110 +1,114 @@ /************************************************************************* RecordThread.h - thread for lowlevel audio recording ------------------- begin : Mon Oct 20 2003 copyright : (C) 2003 by Thomas Eschenbacher email : Thomas.Eschenbacher@gmx.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef RECORD_THREAD_H #define RECORD_THREAD_H #include "config.h" #include +#include #include #include "libkwave/WorkerThread.h" namespace Kwave { class RecordDevice; class RecordThread: public Kwave::WorkerThread { Q_OBJECT public: /** Constructor */ RecordThread(); /** Destructor */ virtual ~RecordThread() Q_DECL_OVERRIDE; /** does the recording */ virtual void run() Q_DECL_OVERRIDE; /** * Select a new record device. * @param device a RecordDevice that is opened and set up for reading * @note this must not be called during recording */ void setRecordDevice(Kwave::RecordDevice *device); /** * Set the number of buffers and their size * @param count the number of buffer, minimum allowed is two * @param size the number of bytes for each buffer * @return number of allocated buffers or -ENOMEM if less than two * @note this must not be called during recording */ int setBuffers(unsigned int count, unsigned int size); /** Returns the amount of remaining empty buffers */ unsigned int remainingBuffers(); /** Returns the number of queued filled buffers */ unsigned int queuedBuffers(); /** De-queues a buffer from the m_full_queue. */ QByteArray dequeue(); signals: /** * emitted when a buffer was full and has been de-queued * with dequeue() */ void bufferFull(); /** * emitted when the recording stops or aborts * @param errorcode zero if stopped normally or a negative * error code if aborted */ void stopped(int errorcode); private: + /** lock for protecting the queues */ + QMutex m_lock; + /** the device used as source */ Kwave::RecordDevice *m_device; /** queue with empty buffers for raw input data */ QQueuem_empty_queue; /** queue with filled buffers with raw input data */ QQueuem_full_queue; /** number of buffers to allocate */ unsigned int m_buffer_count; /** size of m_buffer in bytes */ unsigned int m_buffer_size; }; } #endif /* RECORD_THREAD_H */ //*************************************************************************** //***************************************************************************