diff --git a/CMake/Modules/Findportaudio.cmake b/CMake/Modules/Findportaudio.cmake new file mode 100644 index 000000000..5828e19df --- /dev/null +++ b/CMake/Modules/Findportaudio.cmake @@ -0,0 +1,47 @@ +# - Try to find portaudio +# +# Once done, this will define: +# +# portaudio_FOUND - system has portaudio +# portaudio_INCLUDE_DIRS - the portaudio include directories +# portaudio_LIBRARIES - link these to use portaudio +# portaudio_LIBRARY_DIRS - required shared/dynamic libraries are here +# +# If portaudio_STATIC is TRUE then static linking will be assumed +# + +include (LibFindMacros) + +set (portaudio_LIBRARY_DIRS) + +# pkg-config? +find_path (__portaudio_pc_path NAMES portaudio-2.0.pc + PATH_SUFFIXES lib/pkgconfig lib64/pkgconfig + ) +if (__portaudio_pc_path) + set (__pc_path $ENV{PKG_CONFIG_PATH}) + list (APPEND __pc_path "${__portaudio_pc_path}") + set (ENV{PKG_CONFIG_PATH} "${__pc_path}") + unset (__pc_path CACHE) +endif () +unset (__portaudio_pc_path CACHE) + +# Use pkg-config to get hints about paths, libs and, flags +unset (__pkg_config_checked_hamlib CACHE) +libfind_pkg_check_modules (PORTAUDIO portaudio-2.0) + +if (portaudio_STATIC) + set (portaudio_PROCESS_INCLUDES PORTAUDIO_STATIC_INCLUDE_DIRS) + set (portaudio_PROCESS_LIBS PORTAUDIO_STATIC_LDFLAGS) + set (portaudio_LIBRARY_DIRS ${PORTAUDIO_STATIC_LIBRARY_DIRS}) +else () + set (portaudio_PROCESS_INCLUDES PORTAUDIO_INCLUDE_DIRS) + set (portaudio_PROCESS_LIBS PORTAUDIO_LDFLAGS) + set (portaudio_LIBRARY_DIRS ${PORTAUDIO_LIBRARY_DIRS}) +endif () +libfind_process (portaudio) + +# Handle the QUIETLY and REQUIRED arguments and set PORTAUDIO_FOUND to +# TRUE if all listed variables are TRUE +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (portaudio DEFAULT_MSG portaudio_INCLUDE_DIRS portaudio_LIBRARIES portaudio_LIBRARY_DIRS) diff --git a/CMake/Modules/Findusb.cmake b/CMake/Modules/Findusb.cmake new file mode 100644 index 000000000..6c519c839 --- /dev/null +++ b/CMake/Modules/Findusb.cmake @@ -0,0 +1,57 @@ +# Findusb +# ======= +# +# Find the usb library +# +# This will define the following variables:: +# +# usb_FOUND - True if the system has the usb library +# usb_VERSION - The verion of the usb library which was found +# +# and the following imported targets:: +# +# usb::usb - The libusb library + +find_package (PkgConfig) +pkg_check_modules (PC_usb QUIET usb) + +find_path (usb_INCLUDE_DIR + NAMES libusb.h + PATHS ${PC_usb_INCLUDE_DIRS} + PATH_SUFFIXES libusb-1.0 + ) +find_library (usb_LIBRARY + NAMES libusb-1.0 + PATHS $PC_usb_LIBRARY_DIRS} +) + +set (usb_VERSION ${PC_usb_VERSION}) + +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (usb + FOUND_VAR usb_FOUND + REQUIRED_VARS + usb_LIBRARY + usb_INCLUDE_DIR + VERSION_VAR usb_VERSION + ) + +if (usb_FOUND) + set (usb_LIBRARIES ${usb_LIBRARY}) + set (usb_INCLUDE_DIRS ${usb_INCLUDE_DIR}) + set (usb_DEFINITIONS ${PC_usb_CFLAGS_OTHER}) +endif () + +if (usb_FOUND AND NOT TARGET usb::usb) + add_library (usb::usb UNKNOWN IMPORTED) + set_target_properties (usb::usb PROPERTIES + IMPORTED_LOCATION "${usb_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_usb_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${usb_INCLUDE_DIR}" + ) +endif () + +mark_as_advanced ( + usb_INCLUDE_DIR + usb_LIBRARY + ) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6b55ca78..0d3676c73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -949,7 +949,7 @@ if (Fortran_COMPILER_NAME MATCHES "gfortran.*") endif (CMAKE_OSX_SYSROOT) set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -fbounds-check -funroll-all-loops -fno-f2c ${General_FFLAGS}") - set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -fbounds-check -fno-f2c ${General_FFLAGS}") + set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -fbounds-check -fno-f2c -ffpe-trap=denormal,invalid,zero,overflow ${General_FFLAGS}") elseif (Fortran_COMPILER_NAME MATCHES "ifort.*") # ifort (untested) set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -f77rtl ${General_FFLAGS}") diff --git a/doc/building on MS Windows.txt b/doc/building on MS Windows.txt index 42ea8d0e5..0df690309 100644 --- a/doc/building on MS Windows.txt +++ b/doc/building on MS Windows.txt @@ -19,6 +19,7 @@ Here is an overview list, details are filled out below: * Hamlib rig control library * Pkg Config Lite * Boost C++ libraries + * portaudio library (used by map65) Qt Framework ------------ @@ -80,7 +81,7 @@ installed and updated you will need to install some packages, these are needed to provide the necessary *nix tools and utilities to build Hamlib from sources. - pacman -S autoconf automake libtool make + pacman -S autoconf automake libtool make tar Hamlib ------ @@ -169,3 +170,52 @@ from https://sourceforge.net/projects/pkgconfiglite/files/0.28-1/ and unzip it into a convenient location, as with other ancillary tools and libraries I put these under C:\Tools\. +portaudio +--------- + +This library is only available as sources so must be built. It uses +autotools and building using MinGW tools from an Msys shell is +recommended. Ensure your Msys shell environment (PATH) is correctly +set up for the MinGW tool chain you wish to build with, i.e. the MinGW +tools bundled with the Qt installation for 32-, or 64-bit as required. + +Download the latest stable version sources tarball from +http://files.portaudio.com/download.html , at the time of writing that +was the pa_stable_v190700_20210406.tgz file. Unzip and unpack the +tarball in a suitable location like ~/src : + + cd ~/src + tar xf ~/Downloads/pa_stable_v190700_20210406.tgz + +out-of-source-tree builds are recommended, create a build directory in +a suitable location like ~/build and change working directory to it: + + mkdir -p ~/build/portaudio/mingw64 + cd !$ + +Configure and build and install the library in a suitable place (I use +~/local as a root directory for installed packages. + + ~/src/portaudio/configure --prefix=$(HOME)/local/portaudio/mingw64 --with-winapi=wmme,directx,wdmks CFLAGS=-DNDEBUG + make && make install + +Repeat for the 32-bit architecture if required, using a suitable Msys +environment for the required tool chain, different build directory, +and install location. + +Update your CMake tool chain files to include the install directory, +or directories, above. I have something like this in the 64-bit tool +chain files: + + # ... + set (PORTAUDIODIR C:/Users/bill/local/portaudio/mingw64) + # ... + set (CMAKE_PREFIX_PATH ... ${PORTAUDIODIR} ...) + #... + +and similarly with the 32-bit tool chain file specifying the mingw32 +portaudio installation root directory. + +Note that on Windows portaudio will only build static libraries using +the standard configuration, this is fine and therefore there is no +need to add any new run-time paths to your execution environment. diff --git a/map65/CMakeLists.txt b/map65/CMakeLists.txt index 7bda9fe71..9e1baafeb 100644 --- a/map65/CMakeLists.txt +++ b/map65/CMakeLists.txt @@ -1,3 +1,7 @@ +find_package (portaudio REQUIRED) + +find_package (usb REQUIRED) + set (map65_CXXSRCS about.cpp astro.cpp @@ -46,7 +50,8 @@ add_subdirectory (libm65) qt5_wrap_ui (map65_GENUISRCS ${map65_UISRCS}) add_executable (map65 ${map65_CXXSRCS} ${map65_CSRCS} ${map65_GENUISRCS} map65.rc) -target_link_libraries (map65 m65impl ${FFTW3_LIBRARIES} Qt5::Widgets) +target_include_directories (map65 PRIVATE ${PORTAUDIO_INCLUDE_DIRS}) +target_link_libraries (map65 m65impl ${FFTW3_LIBRARIES} Qt5::Widgets Qt5::Network ${PORTAUDIO_STATIC_LDFLAGS} usb::usb) install ( TARGETS map65 diff --git a/map65/devsetup.cpp b/map65/devsetup.cpp index 5abafaacb..2e223a710 100644 --- a/map65/devsetup.cpp +++ b/map65/devsetup.cpp @@ -27,7 +27,7 @@ void DevSetup::initDlg() int minSpeed[MAXDEVICES]; int maxSpeed[MAXDEVICES]; char hostAPI_DeviceName[MAXDEVICES][50]; - char s[60]; + char s[256]; int numDevices=Pa_GetDeviceCount(); getDev(&numDevices,hostAPI_DeviceName,minChan,maxChan,minSpeed,maxSpeed); k=0; @@ -45,7 +45,7 @@ void DevSetup::initDlg() const PaDeviceInfo *pdi; int nchout; char *p,*p1; - char p2[50]; + char p2[256]; char pa_device_name[128]; char pa_device_hostapi[128]; diff --git a/map65/fftw3.f b/map65/fftw3.f deleted file mode 100644 index 3410184ca..000000000 --- a/map65/fftw3.f +++ /dev/null @@ -1,64 +0,0 @@ - INTEGER FFTW_R2HC - PARAMETER (FFTW_R2HC=0) - INTEGER FFTW_HC2R - PARAMETER (FFTW_HC2R=1) - INTEGER FFTW_DHT - PARAMETER (FFTW_DHT=2) - INTEGER FFTW_REDFT00 - PARAMETER (FFTW_REDFT00=3) - INTEGER FFTW_REDFT01 - PARAMETER (FFTW_REDFT01=4) - INTEGER FFTW_REDFT10 - PARAMETER (FFTW_REDFT10=5) - INTEGER FFTW_REDFT11 - PARAMETER (FFTW_REDFT11=6) - INTEGER FFTW_RODFT00 - PARAMETER (FFTW_RODFT00=7) - INTEGER FFTW_RODFT01 - PARAMETER (FFTW_RODFT01=8) - INTEGER FFTW_RODFT10 - PARAMETER (FFTW_RODFT10=9) - INTEGER FFTW_RODFT11 - PARAMETER (FFTW_RODFT11=10) - INTEGER FFTW_FORWARD - PARAMETER (FFTW_FORWARD=-1) - INTEGER FFTW_BACKWARD - PARAMETER (FFTW_BACKWARD=+1) - INTEGER FFTW_MEASURE - PARAMETER (FFTW_MEASURE=0) - INTEGER FFTW_DESTROY_INPUT - PARAMETER (FFTW_DESTROY_INPUT=1) - INTEGER FFTW_UNALIGNED - PARAMETER (FFTW_UNALIGNED=2) - INTEGER FFTW_CONSERVE_MEMORY - PARAMETER (FFTW_CONSERVE_MEMORY=4) - INTEGER FFTW_EXHAUSTIVE - PARAMETER (FFTW_EXHAUSTIVE=8) - INTEGER FFTW_PRESERVE_INPUT - PARAMETER (FFTW_PRESERVE_INPUT=16) - INTEGER FFTW_PATIENT - PARAMETER (FFTW_PATIENT=32) - INTEGER FFTW_ESTIMATE - PARAMETER (FFTW_ESTIMATE=64) - INTEGER FFTW_ESTIMATE_PATIENT - PARAMETER (FFTW_ESTIMATE_PATIENT=128) - INTEGER FFTW_BELIEVE_PCOST - PARAMETER (FFTW_BELIEVE_PCOST=256) - INTEGER FFTW_DFT_R2HC_ICKY - PARAMETER (FFTW_DFT_R2HC_ICKY=512) - INTEGER FFTW_NONTHREADED_ICKY - PARAMETER (FFTW_NONTHREADED_ICKY=1024) - INTEGER FFTW_NO_BUFFERING - PARAMETER (FFTW_NO_BUFFERING=2048) - INTEGER FFTW_NO_INDIRECT_OP - PARAMETER (FFTW_NO_INDIRECT_OP=4096) - INTEGER FFTW_ALLOW_LARGE_GENERIC - PARAMETER (FFTW_ALLOW_LARGE_GENERIC=8192) - INTEGER FFTW_NO_RANK_SPLITS - PARAMETER (FFTW_NO_RANK_SPLITS=16384) - INTEGER FFTW_NO_VRANK_SPLITS - PARAMETER (FFTW_NO_VRANK_SPLITS=32768) - INTEGER FFTW_NO_VRECURSE - PARAMETER (FFTW_NO_VRECURSE=65536) - INTEGER FFTW_NO_SIMD - PARAMETER (FFTW_NO_SIMD=131072) diff --git a/map65/libfftw3f_win.a b/map65/libfftw3f_win.a deleted file mode 100644 index 9176f43f9..000000000 Binary files a/map65/libfftw3f_win.a and /dev/null differ diff --git a/map65/libm65/CMakeLists.txt b/map65/libm65/CMakeLists.txt index ae9b79bfb..9dcd8475c 100644 --- a/map65/libm65/CMakeLists.txt +++ b/map65/libm65/CMakeLists.txt @@ -32,6 +32,7 @@ set (libm65_FSRCS ftninit.f90 ftnquit.f90 q65b.f90 + gen65.f90 gen_q65_wave.f90 genqra64a.f90 geocentric.f90 diff --git a/map65/libusb.a b/map65/libusb.a deleted file mode 100644 index d98baac50..000000000 Binary files a/map65/libusb.a and /dev/null differ diff --git a/map65/libwsock32.a b/map65/libwsock32.a deleted file mode 100644 index 0d6d7c8f9..000000000 Binary files a/map65/libwsock32.a and /dev/null differ diff --git a/map65/main.cpp b/map65/main.cpp index 3c045f667..6498827d2 100644 --- a/map65/main.cpp +++ b/map65/main.cpp @@ -7,10 +7,22 @@ #include "mainwindow.h" +static QtMessageHandler default_message_handler; + +void my_message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg) +{ + // Handle the messages! + + // Call the default handler. + (*default_message_handler) (type, context, msg); +} + int main(int argc, char *argv[]) { - QApplication a(argc, argv); - MainWindow w; - w.show(); - return a.exec(); + default_message_handler = qInstallMessageHandler (my_message_handler); + + QApplication a {argc, argv}; + MainWindow w; + w.show (); + return a.exec (); } diff --git a/map65/mainwindow.cpp b/map65/mainwindow.cpp index 7e9ccd2b0..89be6b771 100644 --- a/map65/mainwindow.cpp +++ b/map65/mainwindow.cpp @@ -10,7 +10,7 @@ #include "bandmap.h" #include "txtune.h" #include "sleep.h" -#include "portaudio.h" +#include #define NFFT 32768 @@ -1308,11 +1308,11 @@ void MainWindow::decode() //decode() QString hcall=(ui->dxCallEntry->text()+" ").mid(0,12); QString hgrid=(ui->dxGridEntry->text()+" ").mid(0,6); - strncpy(datcom_.mycall, mcall.toLatin1(), 12); - strncpy(datcom_.mygrid, mgrid.toLatin1(), 6); - strncpy(datcom_.hiscall, hcall.toLatin1(), 12); - strncpy(datcom_.hisgrid, hgrid.toLatin1(), 6); - strncpy(datcom_.datetime, m_dateTime.toLatin1(), 20); + memcpy(datcom_.mycall, mcall.toLatin1(), 12); + memcpy(datcom_.mygrid, mgrid.toLatin1(), 6); + memcpy(datcom_.hiscall, hcall.toLatin1(), 12); + memcpy(datcom_.hisgrid, hgrid.toLatin1(), 6); + memcpy(datcom_.datetime, m_dateTime.toLatin1(), 20); //newdat=1 ==> this is new data, must do the big FFT //nagain=1 ==> decode only at fQSO +/- Tol @@ -1661,14 +1661,14 @@ void MainWindow::ba2msg(QByteArray ba, char message[]) //ba2msg() bool eom; eom=false; for(int i=0;i<22; i++) { - if((int)ba[i] == 0) eom=true; + if (i >= ba.size () || !ba[i]) eom=true; if(eom) { - message[i]=32; + message[i] = ' '; } else { message[i]=ba[i]; } } - message[22]=0; + message[22] = '\0'; } void MainWindow::on_txFirstCheckBox_stateChanged(int nstate) //TxFirst diff --git a/map65/meterwidget.cpp b/map65/meterwidget.cpp index b48aa65d0..8e48ed57d 100755 --- a/map65/meterwidget.cpp +++ b/map65/meterwidget.cpp @@ -32,9 +32,7 @@ void MeterWidget::setValue(int value) void MeterWidget::paintEvent( QPaintEvent * ) { int pos; - QPainter p; - - p.begin(this); + QPainter p {this}; // Sanitize m_signal = m_signal < 0 ? 0 : m_signal; diff --git a/map65/paInputDevice.c b/map65/paInputDevice.c index 7cf305134..bad4973f4 100644 --- a/map65/paInputDevice.c +++ b/map65/paInputDevice.c @@ -14,7 +14,7 @@ void paInputDevice(int id, char* hostAPI_DeviceName, int* minChan, int pa_device_min_bytes; int pa_device_max_channels; int pa_device_min_channels; - char p2[50]; + char p2[256]; char *p,*p1; static int iret, valid_dev_cnt; diff --git a/map65/pa_get_device_info.c b/map65/pa_get_device_info.c index ac6bc9ffc..968d3434b 100644 --- a/map65/pa_get_device_info.c +++ b/map65/pa_get_device_info.c @@ -1,5 +1,6 @@ #include #include +#include #define MAX_LATENCY 20 diff --git a/map65/palir-02.dll b/map65/palir-02.dll deleted file mode 100644 index 925939d3d..000000000 Binary files a/map65/palir-02.dll and /dev/null differ diff --git a/map65/plotter.cpp b/map65/plotter.cpp index ecc4f8865..9527a2457 100644 --- a/map65/plotter.cpp +++ b/map65/plotter.cpp @@ -285,7 +285,6 @@ void CPlotter::DrawOverlay() //DrawOverlay() QRect rect0; QPainter painter0(&m_ScalePixmap); - painter0.begin (this); //create Font to use for scales QFont Font("Arial"); @@ -365,7 +364,6 @@ void CPlotter::DrawOverlay() //DrawOverlay() // Now make the zoomed scale, using m_ZoomScalePixmap and painter3 QRect rect1; QPainter painter3(&m_ZoomScalePixmap); - painter3.begin (this); painter3.setFont(Font); painter3.setPen(Qt::black); diff --git a/map65/portaudio.h b/map65/portaudio.h deleted file mode 100755 index 250fba021..000000000 --- a/map65/portaudio.h +++ /dev/null @@ -1,1123 +0,0 @@ - -#ifndef PORTAUDIO_H -#define PORTAUDIO_H -/* - * $Id: portaudio.h,v 1.1 2005/11/29 21:27:24 joe Exp $ - * PortAudio Portable Real-Time Audio Library - * PortAudio API Header File - * Latest version available at: http://www.portaudio.com/ - * - * Copyright (c) 1999-2002 Ross Bencina and Phil Burk - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Any person wishing to distribute modifications to the Software is - * requested to send the modifications to the original developer so that - * they can be incorporated into the canonical version. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/** @file - @brief The PortAudio API. -*/ - - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - - -/** Retrieve the release number of the currently running PortAudio build, - eg 1900. -*/ -int Pa_GetVersion( void ); - - -/** Retrieve a textual description of the current PortAudio build, - eg "PortAudio V19-devel 13 October 2002". -*/ -const char* Pa_GetVersionText( void ); - - -/** Error codes returned by PortAudio functions. - Note that with the exception of paNoError, all PaErrorCodes are negative. -*/ - -typedef int PaError; -typedef enum PaErrorCode -{ - paNoError = 0, - - paNotInitialized = -10000, - paUnanticipatedHostError, - paInvalidChannelCount, - paInvalidSampleRate, - paInvalidDevice, - paInvalidFlag, - paSampleFormatNotSupported, - paBadIODeviceCombination, - paInsufficientMemory, - paBufferTooBig, - paBufferTooSmall, - paNullCallback, - paBadStreamPtr, - paTimedOut, - paInternalError, - paDeviceUnavailable, - paIncompatibleHostApiSpecificStreamInfo, - paStreamIsStopped, - paStreamIsNotStopped, - paInputOverflowed, - paOutputUnderflowed, - paHostApiNotFound, - paInvalidHostApi, - paCanNotReadFromACallbackStream, /**< @todo review error code name */ - paCanNotWriteToACallbackStream, /**< @todo review error code name */ - paCanNotReadFromAnOutputOnlyStream, /**< @todo review error code name */ - paCanNotWriteToAnInputOnlyStream, /**< @todo review error code name */ - paIncompatibleStreamHostApi -} PaErrorCode; - - -/** Translate the supplied PortAudio error code into a human readable - message. -*/ -const char *Pa_GetErrorText( PaError errorCode ); - - -/** Library initialization function - call this before using PortAudio. - This function initialises internal data structures and prepares underlying - host APIs for use. This function MUST be called before using any other - PortAudio API functions. - - If Pa_Initialize() is called multiple times, each successful - call must be matched with a corresponding call to Pa_Terminate(). - Pairs of calls to Pa_Initialize()/Pa_Terminate() may overlap, and are not - required to be fully nested. - - Note that if Pa_Initialize() returns an error code, Pa_Terminate() should - NOT be called. - - @return paNoError if successful, otherwise an error code indicating the cause - of failure. - - @see Pa_Terminate -*/ -PaError Pa_Initialize( void ); - - -/** Library termination function - call this when finished using PortAudio. - This function deallocates all resources allocated by PortAudio since it was - initializied by a call to Pa_Initialize(). In cases where Pa_Initialise() has - been called multiple times, each call must be matched with a corresponding call - to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically - close any PortAudio streams that are still open. - - Pa_Terminate() MUST be called before exiting a program which uses PortAudio. - Failure to do so may result in serious resource leaks, such as audio devices - not being available until the next reboot. - - @return paNoError if successful, otherwise an error code indicating the cause - of failure. - - @see Pa_Initialize -*/ -PaError Pa_Terminate( void ); - - - -/** The type used to refer to audio devices. Values of this type usually - range from 0 to (Pa_DeviceCount-1), and may also take on the PaNoDevice - and paUseHostApiSpecificDeviceSpecification values. - - @see Pa_DeviceCount, paNoDevice, paUseHostApiSpecificDeviceSpecification -*/ -typedef int PaDeviceIndex; - - -/** A special PaDeviceIndex value indicating that no device is available, - or should be used. - - @see PaDeviceIndex -*/ -#define paNoDevice ((PaDeviceIndex)-1) - - -/** A special PaDeviceIndex value indicating that the device(s) to be used - are specified in the host api specific stream info structure. - - @see PaDeviceIndex -*/ -#define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2) - - -/* Host API enumeration mechanism */ - -/** The type used to enumerate to host APIs at runtime. Values of this type - range from 0 to (Pa_GetHostApiCount()-1). - - @see Pa_GetHostApiCount -*/ -typedef int PaHostApiIndex; - - -/** Retrieve the number of available host APIs. Even if a host API is - available it may have no devices available. - - @return A non-negative value indicating the number of available host APIs - or, a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. - - @see PaHostApiIndex -*/ -PaHostApiIndex Pa_GetHostApiCount( void ); - - -/** Retrieve the index of the default host API. The default host API will be - the lowest common denominator host API on the current platform and is - unlikely to provide the best performance. - - @return A non-negative value ranging from 0 to (Pa_GetHostApiCount()-1) - indicating the default host API index or, a PaErrorCode (which are always - negative) if PortAudio is not initialized or an error is encountered. -*/ -PaHostApiIndex Pa_GetDefaultHostApi( void ); - - -/** Unchanging unique identifiers for each supported host API. This type - is used in the PaHostApiInfo structure. The values are guaranteed to be - unique and to never change, thus allowing code to be written that - conditionally uses host API specific extensions. - - New type ids will be allocated when support for a host API reaches - "public alpha" status, prior to that developers should use the - paInDevelopment type id. - - @see PaHostApiInfo -*/ -typedef enum PaHostApiTypeId -{ - paInDevelopment=0, /* use while developing support for a new host API */ - paDirectSound=1, - paMME=2, - paASIO=3, - paSoundManager=4, - paCoreAudio=5, - paOSS=7, - paALSA=8, - paAL=9, - paBeOS=10, - paWDMKS=11, - paJACK=12 -} PaHostApiTypeId; - - -/** A structure containing information about a particular host API. */ - -typedef struct PaHostApiInfo -{ - /** this is struct version 1 */ - int structVersion; - /** The well known unique identifier of this host API @see PaHostApiTypeId */ - PaHostApiTypeId type; - /** A textual description of the host API for display on user interfaces. */ - const char *name; - - /** The number of devices belonging to this host API. This field may be - used in conjunction with Pa_HostApiDeviceIndexToDeviceIndex() to enumerate - all devices for this host API. - @see Pa_HostApiDeviceIndexToDeviceIndex - */ - int deviceCount; - - /** The the default input device for this host API. The value will be a - device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice - if no default input device is available. - */ - PaDeviceIndex defaultInputDevice; - - /** The the default output device for this host API. The value will be a - device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice - if no default output device is available. - */ - PaDeviceIndex defaultOutputDevice; - -} PaHostApiInfo; - - -/** Retrieve a pointer to a structure containing information about a specific - host Api. - - @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) - - @return A pointer to an immutable PaHostApiInfo structure describing - a specific host API. If the hostApi parameter is out of range or an error - is encountered, the function returns NULL. - - The returned structure is owned by the PortAudio implementation and must not - be manipulated or freed. The pointer is only guaranteed to be valid between - calls to Pa_Initialize() and Pa_Terminate(). -*/ -const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi ); - - -/** Convert a static host API unique identifier, into a runtime - host API index. - - @param type A unique host API identifier belonging to the PaHostApiTypeId - enumeration. - - @return A valid PaHostApiIndex ranging from 0 to (Pa_GetHostApiCount()-1) or, - a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. - - The paHostApiNotFound error code indicates that the host API specified by the - type parameter is not available. - - @see PaHostApiTypeId -*/ -PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type ); - - -/** Convert a host-API-specific device index to standard PortAudio device index. - This function may be used in conjunction with the deviceCount field of - PaHostApiInfo to enumerate all devices for the specified host API. - - @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) - - @param hostApiDeviceIndex A valid per-host device index in the range - 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1) - - @return A non-negative PaDeviceIndex ranging from 0 to (Pa_GetDeviceCount()-1) - or, a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. - - A paInvalidHostApi error code indicates that the host API index specified by - the hostApi parameter is out of range. - - A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter - is out of range. - - @see PaHostApiInfo -*/ -PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, - int hostApiDeviceIndex ); - - - -/** Structure used to return information about a host error condition. -*/ -typedef struct PaHostErrorInfo{ - PaHostApiTypeId hostApiType; /**< the host API which returned the error code */ - long errorCode; /**< the error code returned */ - const char *errorText; /**< a textual description of the error if available, otherwise a zero-length string */ -}PaHostErrorInfo; - - -/** Return information about the last host error encountered. The error - information returned by Pa_GetLastHostErrorInfo() will never be modified - asyncronously by errors occurring in other PortAudio owned threads - (such as the thread that manages the stream callback.) - - This function is provided as a last resort, primarily to enhance debugging - by providing clients with access to all available error information. - - @return A pointer to an immutable structure constaining information about - the host error. The values in this structure will only be valid if a - PortAudio function has previously returned the paUnanticipatedHostError - error code. -*/ -const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void ); - - - -/* Device enumeration and capabilities */ - -/** Retrieve the number of available devices. The number of available devices - may be zero. - - @return A non-negative value indicating the number of available devices or, - a PaErrorCode (which are always negative) if PortAudio is not initialized - or an error is encountered. -*/ -PaDeviceIndex Pa_GetDeviceCount( void ); - - -/** Retrieve the index of the default input device. The result can be - used in the inputDevice parameter to Pa_OpenStream(). - - @return The default input device index for the default host API, or paNoDevice - if no default input device is available or an error was encountered. -*/ -PaDeviceIndex Pa_GetDefaultInputDevice( void ); - - -/** Retrieve the index of the default output device. The result can be - used in the outputDevice parameter to Pa_OpenStream(). - - @return The default output device index for the defualt host API, or paNoDevice - if no default output device is available or an error was encountered. - - @note - On the PC, the user can specify a default device by - setting an environment variable. For example, to use device #1. -
- set PA_RECOMMENDED_OUTPUT_DEVICE=1
-
- The user should first determine the available device ids by using - the supplied application "pa_devs". -*/ -PaDeviceIndex Pa_GetDefaultOutputDevice( void ); - - -/** The type used to represent monotonic time in seconds that can be used - for syncronisation. The type is used for the outTime argument to the - PaStreamCallback and as the result of Pa_GetStreamTime(). - - @see PaStreamCallback, Pa_GetStreamTime -*/ -typedef double PaTime; - - -/** A type used to specify one or more sample formats. Each value indicates - a possible format for sound data passed to and from the stream callback, - Pa_ReadStream and Pa_WriteStream. - - The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8 - and aUInt8 are usually implemented by all implementations. - - The floating point representation (paFloat32) uses +1.0 and -1.0 as the - maximum and minimum respectively. - - paUInt8 is an unsigned 8 bit format where 128 is considered "ground" - - The paNonInterleaved flag indicates that a multichannel buffer is passed - as a set of non-interleaved pointers. - - @see Pa_OpenStream, Pa_OpenDefaultStream, PaDeviceInfo - @see paFloat32, paInt16, paInt32, paInt24, paInt8 - @see paUInt8, paCustomFormat, paNonInterleaved -*/ -typedef unsigned long PaSampleFormat; - - -#define paFloat32 ((PaSampleFormat) 0x00000001) /**< @see PaSampleFormat */ -#define paInt32 ((PaSampleFormat) 0x00000002) /**< @see PaSampleFormat */ -#define paInt24 ((PaSampleFormat) 0x00000004) /**< Packed 24 bit format. @see PaSampleFormat */ -#define paInt16 ((PaSampleFormat) 0x00000008) /**< @see PaSampleFormat */ -#define paInt8 ((PaSampleFormat) 0x00000010) /**< @see PaSampleFormat */ -#define paUInt8 ((PaSampleFormat) 0x00000020) /**< @see PaSampleFormat */ -#define paCustomFormat ((PaSampleFormat) 0x00010000)/**< @see PaSampleFormat */ - -#define paNonInterleaved ((PaSampleFormat) 0x80000000) - -/** A structure providing information and capabilities of PortAudio devices. - Devices may support input, output or both input and output. -*/ -typedef struct PaDeviceInfo -{ - int structVersion; /* this is struct version 2 */ - const char *name; - PaHostApiIndex hostApi; /* note this is a host API index, not a type id*/ - - int maxInputChannels; - int maxOutputChannels; - - /* Default latency values for interactive performance. */ - PaTime defaultLowInputLatency; - PaTime defaultLowOutputLatency; - /* Default latency values for robust non-interactive applications (eg. playing sound files). */ - PaTime defaultHighInputLatency; - PaTime defaultHighOutputLatency; - - double defaultSampleRate; -} PaDeviceInfo; - - -/** Retrieve a pointer to a PaDeviceInfo structure containing information - about the specified device. - @return A pointer to an immutable PaDeviceInfo structure. If the device - parameter is out of range the function returns NULL. - - @param device A valid device index in the range 0 to (Pa_GetDeviceCount()-1) - - @note PortAudio manages the memory referenced by the returned pointer, - the client must not manipulate or free the memory. The pointer is only - guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate(). - - @see PaDeviceInfo, PaDeviceIndex -*/ -const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device ); - - -/** Parameters for one direction (input or output) of a stream. -*/ -typedef struct PaStreamParameters -{ - /** A valid device index in the range 0 to (Pa_GetDeviceCount()-1) - specifying the device to be used or the special constant - paUseHostApiSpecificDeviceSpecification which indicates that the actual - device(s) to use are specified in hostApiSpecificStreamInfo. - This field must not be set to paNoDevice. - */ - PaDeviceIndex device; - - /** The number of channels of sound to be delivered to the - stream callback or accessed by Pa_ReadStream() or Pa_WriteStream(). - It can range from 1 to the value of maxInputChannels in the - PaDeviceInfo record for the device specified by the device parameter. - */ - int channelCount; - - /** The sample format of the buffer provided to the stream callback, - a_ReadStream() or Pa_WriteStream(). It may be any of the formats described - by the PaSampleFormat enumeration. - */ - PaSampleFormat sampleFormat; - - /** The desired latency in seconds. Where practical, implementations should - configure their latency based on these parameters, otherwise they may - choose the closest viable latency instead. Unless the suggested latency - is greater than the absolute upper limit for the device implementations - shouldround the suggestedLatency up to the next practial value - ie to - provide an equal or higher latency than suggestedLatency whereever possibe. - Actual latency values for an open stream may be retrieved using the - inputLatency and outputLatency fields of the PaStreamInfo structure - returned by Pa_GetStreamInfo(). - @see default*Latency in PaDeviceInfo, *Latency in PaStreamInfo - */ - PaTime suggestedLatency; - - /** An optional pointer to a host api specific data structure - containing additional information for device setup and/or stream processing. - hostApiSpecificStreamInfo is never required for correct operation, - if not used it should be set to NULL. - */ - void *hostApiSpecificStreamInfo; - -} PaStreamParameters; - - -/** Return code for Pa_IsFormatSupported indicating success. */ -#define paFormatIsSupported (0) - -/** Determine whether it would be possible to open a stream with the specified - parameters. - - @param inputParameters A structure that describes the input parameters used to - open a stream. The suggestedLatency field is ignored. See PaStreamParameters - for a description of these parameters. inputParameters must be NULL for - output-only streams. - - @param outputParameters A structure that describes the output parameters used - to open a stream. The suggestedLatency field is ignored. See PaStreamParameters - for a description of these parameters. outputParameters must be NULL for - input-only streams. - - @param sampleRate The required sampleRate. For full-duplex streams it is the - sample rate for both input and output - - @return Returns 0 if the format is supported, and an error code indicating why - the format is not supported otherwise. The constant paFormatIsSupported is - provided to compare with the return value for success. - - @see paFormatIsSupported, PaStreamParameters -*/ -PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, - const PaStreamParameters *outputParameters, - double sampleRate ); - - - -/* Streaming types and functions */ - - -/** - A single PaStream can provide multiple channels of real-time - streaming audio input and output to a client application. A stream - provides access to audio hardware represented by one or more - PaDevices. Depending on the underlying Host API, it may be possible - to open multiple streams using the same device, however this behavior - is implementation defined. Portable applications should assume that - a PaDevice may be simultaneously used by at most one PaStream. - - Pointers to PaStream objects are passed between PortAudio functions that - operate on streams. - - @see Pa_OpenStream, Pa_OpenDefaultStream, Pa_OpenDefaultStream, Pa_CloseStream, - Pa_StartStream, Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive, - Pa_GetStreamTime, Pa_GetStreamCpuLoad - -*/ -typedef void PaStream; - - -/** Can be passed as the framesPerBuffer parameter to Pa_OpenStream() - or Pa_OpenDefaultStream() to indicate that the stream callback will - accept buffers of any size. -*/ -#define paFramesPerBufferUnspecified (0) - - -/** Flags used to control the behavior of a stream. They are passed as - parameters to Pa_OpenStream or Pa_OpenDefaultStream. Multiple flags may be - ORed together. - - @see Pa_OpenStream, Pa_OpenDefaultStream - @see paNoFlag, paClipOff, paDitherOff, paNeverDropInput, - paPrimeOutputBuffersUsingStreamCallback, paPlatformSpecificFlags -*/ -typedef unsigned long PaStreamFlags; - -/** @see PaStreamFlags */ -#define paNoFlag ((PaStreamFlags) 0) - -/** Disable default clipping of out of range samples. - @see PaStreamFlags -*/ -#define paClipOff ((PaStreamFlags) 0x00000001) - -/** Disable default dithering. - @see PaStreamFlags -*/ -#define paDitherOff ((PaStreamFlags) 0x00000002) - -/** Flag requests that where possible a full duplex stream will not discard - overflowed input samples without calling the stream callback. This flag is - only valid for full duplex callback streams and only when used in combination - with the paFramesPerBufferUnspecified (0) framesPerBuffer parameter. Using - this flag incorrectly results in a paInvalidFlag error being returned from - Pa_OpenStream and Pa_OpenDefaultStream. - - @see PaStreamFlags, paFramesPerBufferUnspecified -*/ -#define paNeverDropInput ((PaStreamFlags) 0x00000004) - -/** Call the stream callback to fill initial output buffers, rather than the - default behavior of priming the buffers with zeros (silence). This flag has - no effect for input-only and blocking read/write streams. - - @see PaStreamFlags -*/ -#define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008) - -/** A mask specifying the platform specific bits. - @see PaStreamFlags -*/ -#define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000) - -/** - Timing information for the buffers passed to the stream callback. -*/ -typedef struct PaStreamCallbackTimeInfo{ - PaTime inputBufferAdcTime; - PaTime currentTime; - PaTime outputBufferDacTime; -} PaStreamCallbackTimeInfo; - - -/** - Flag bit constants for the statusFlags to PaStreamCallback. - - @see paInputUnderflow, paInputOverflow, paOutputUnderflow, paOutputOverflow, - paPrimingOutput -*/ -typedef unsigned long PaStreamCallbackFlags; - -/** In a stream opened with paFramesPerBufferUnspecified, indicates that - input data is all silence (zeros) because no real data is available. In a - stream opened without paFramesPerBufferUnspecified, it indicates that one or - more zero samples have been inserted into the input buffer to compensate - for an input underflow. - @see PaStreamCallbackFlags -*/ -#define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001) - -/** In a stream opened with paFramesPerBufferUnspecified, indicates that data - prior to the first sample of the input buffer was discarded due to an - overflow, possibly because the stream callback is using too much CPU time. - Otherwise indicates that data prior to one or more samples in the - input buffer was discarded. - @see PaStreamCallbackFlags -*/ -#define paInputOverflow ((PaStreamCallbackFlags) 0x00000002) - -/** Indicates that output data (or a gap) was inserted, possibly because the - stream callback is using too much CPU time. - @see PaStreamCallbackFlags -*/ -#define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004) - -/** Indicates that output data will be discarded because no room is available. - @see PaStreamCallbackFlags -*/ -#define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008) - -/** Some of all of the output data will be used to prime the stream, input - data may be zero. - @see PaStreamCallbackFlags -*/ -#define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010) - -/** - Allowable return values for the PaStreamCallback. - @see PaStreamCallback -*/ -typedef enum PaStreamCallbackResult -{ - paContinue=0, - paComplete=1, - paAbort=2 -} PaStreamCallbackResult; - - -/** - Functions of type PaStreamCallback are implemented by PortAudio clients. - They consume, process or generate audio in response to requests from an - active PortAudio stream. - - @param input and @param output are arrays of interleaved samples, - the format, packing and number of channels used by the buffers are - determined by parameters to Pa_OpenStream(). - - @param frameCount The number of sample frames to be processed by - the stream callback. - - @param timeInfo The time in seconds when the first sample of the input - buffer was received at the audio input, the time in seconds when the first - sample of the output buffer will begin being played at the audio output, and - the time in seconds when the stream callback was called. - See also Pa_GetStreamTime() - - @param statusFlags Flags indicating whether input and/or output buffers - have been inserted or will be dropped to overcome underflow or overflow - conditions. - - @param userData The value of a user supplied pointer passed to - Pa_OpenStream() intended for storing synthesis data etc. - - @return - The stream callback should return one of the values in the - PaStreamCallbackResult enumeration. To ensure that the callback continues - to be called, it should return paContinue (0). Either paComplete or paAbort - can be returned to finish stream processing, after either of these values is - returned the callback will not be called again. If paAbort is returned the - stream will finish as soon as possible. If paComplete is returned, the stream - will continue until all buffers generated by the callback have been played. - This may be useful in applications such as soundfile players where a specific - duration of output is required. However, it is not necessary to utilise this - mechanism as Pa_StopStream(), Pa_AbortStream() or Pa_CloseStream() can also - be used to stop the stream. The callback must always fill the entire output - buffer irrespective of its return value. - - @see Pa_OpenStream, Pa_OpenDefaultStream - - @note With the exception of Pa_GetStreamCpuLoad() it is not permissable to call - PortAudio API functions from within the stream callback. -*/ -typedef int PaStreamCallback( - const void *input, void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData ); - - -/** Opens a stream for either input, output or both. - - @param stream The address of a PaStream pointer which will receive - a pointer to the newly opened stream. - - @param inputParameters A structure that describes the input parameters used by - the opened stream. See PaStreamParameters for a description of these parameters. - inputParameters must be NULL for output-only streams. - - @param outputParameters A structure that describes the output parameters used by - the opened stream. See PaStreamParameters for a description of these parameters. - outputParameters must be NULL for input-only streams. - - @param sampleRate The desired sampleRate. For full-duplex streams it is the - sample rate for both input and output - - @param framesPerBuffer The number of frames passed to the stream callback - function, or the preferred block granularity for a blocking read/write stream. - The special value paFramesPerBufferUnspecified (0) may be used to request that - the stream callback will recieve an optimal (and possibly varying) number of - frames based on host requirements and the requested latency settings. - Note: With some host APIs, the use of non-zero framesPerBuffer for a callback - stream may introduce an additional layer of buffering which could introduce - additional latency. PortAudio guarantees that the additional latency - will be kept to the theoretical minimum however, it is strongly recommended - that a non-zero framesPerBuffer value only be used when your algorithm - requires a fixed number of frames per stream callback. - - @param streamFlags Flags which modify the behaviour of the streaming process. - This parameter may contain a combination of flags ORed together. Some flags may - only be relevant to certain buffer formats. - - @param streamCallback A pointer to a client supplied function that is responsible - for processing and filling input and output buffers. If this parameter is NULL - the stream will be opened in 'blocking read/write' mode. In blocking mode, - the client can receive sample data using Pa_ReadStream and write sample data - using Pa_WriteStream, the number of samples that may be read or written - without blocking is returned by Pa_GetStreamReadAvailable and - Pa_GetStreamWriteAvailable respectively. - - @param userData A client supplied pointer which is passed to the stream callback - function. It could for example, contain a pointer to instance data necessary - for processing the audio buffers. This parameter is ignored if streamCallback - is NULL. - - @return - Upon success Pa_OpenStream() returns paNoError and places a pointer to a - valid PaStream in the stream argument. The stream is inactive (stopped). - If a call to Pa_OpenStream() fails, a non-zero error code is returned (see - PaError for possible error codes) and the value of stream is invalid. - - @see PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream, - Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable -*/ -PaError Pa_OpenStream( PaStream** stream, - const PaStreamParameters *inputParameters, - const PaStreamParameters *outputParameters, - double sampleRate, - unsigned long framesPerBuffer, - PaStreamFlags streamFlags, - PaStreamCallback *streamCallback, - void *userData ); - - -/** A simplified version of Pa_OpenStream() that opens the default input - and/or output devices. - - @param stream The address of a PaStream pointer which will receive - a pointer to the newly opened stream. - - @param numInputChannels The number of channels of sound that will be supplied - to the stream callback or returned by Pa_ReadStream. It can range from 1 to - the value of maxInputChannels in the PaDeviceInfo record for the default input - device. If 0 the stream is opened as an output-only stream. - - @param numOutputChannels The number of channels of sound to be delivered to the - stream callback or passed to Pa_WriteStream. It can range from 1 to the value - of maxOutputChannels in the PaDeviceInfo record for the default output dvice. - If 0 the stream is opened as an output-only stream. - - @param sampleFormat The sample format of both the input and output buffers - provided to the callback or passed to and from Pa_ReadStream and Pa_WriteStream. - sampleFormat may be any of the formats described by the PaSampleFormat - enumeration. - - @param sampleRate Same as Pa_OpenStream parameter of the same name. - @param framesPerBuffer Same as Pa_OpenStream parameter of the same name. - @param streamCallback Same as Pa_OpenStream parameter of the same name. - @param userData Same as Pa_OpenStream parameter of the same name. - - @return As for Pa_OpenStream - - @see Pa_OpenStream, PaStreamCallback -*/ -PaError Pa_OpenDefaultStream( PaStream** stream, - int numInputChannels, - int numOutputChannels, - PaSampleFormat sampleFormat, - double sampleRate, - unsigned long framesPerBuffer, - PaStreamCallback *streamCallback, - void *userData ); - - -/** Closes an audio stream. If the audio stream is active it - discards any pending buffers as if Pa_AbortStream() had been called. -*/ -PaError Pa_CloseStream( PaStream *stream ); - - -/** Functions of type PaStreamFinishedCallback are implemented by PortAudio - clients. They can be registered with a stream using the Pa_SetStreamFinishedCallback - function. Once registered they are called when the stream becomes inactive - (ie once a call to Pa_StopStream() will not block). - A stream will become inactive after the stream callback returns non-zero, - or when Pa_StopStream or Pa_AbortStream is called. For a stream providing audio - output, if the stream callback returns paComplete, or Pa_StopStream is called, - the stream finished callback will not be called until all generated sample data - has been played. - - @param userData The userData parameter supplied to Pa_OpenStream() - - @see Pa_SetStreamFinishedCallback -*/ -typedef void PaStreamFinishedCallback( void *userData ); - - -/** Register a stream finished callback function which will be called when the - stream becomes inactive. See the description of PaStreamFinishedCallback for - further details about when the callback will be called. - - @param stream a pointer to a PaStream that is in the stopped state - if the - stream is not stopped, the stream's finished callback will remain unchanged - and an error code will be returned. - - @param streamFinishedCallback a pointer to a function with the same signature - as PaStreamFinishedCallback, that will be called when the stream becomes - inactive. Passing NULL for this parameter will un-register a previously - registered stream finished callback function. - - @return on success returns paNoError, otherwise an error code indicating the cause - of the error. - - @see PaStreamFinishedCallback -*/ -PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); - - -/** Commences audio processing. -*/ -PaError Pa_StartStream( PaStream *stream ); - - -/** Terminates audio processing. It waits until all pending - audio buffers have been played before it returns. -*/ -PaError Pa_StopStream( PaStream *stream ); - - -/** Terminates audio processing immediately without waiting for pending - buffers to complete. -*/ -PaError Pa_AbortStream( PaStream *stream ); - - -/** Determine whether the stream is stopped. - A stream is considered to be stopped prior to a successful call to - Pa_StartStream and after a successful call to Pa_StopStream or Pa_AbortStream. - If a stream callback returns a value other than paContinue the stream is NOT - considered to be stopped. - - @return Returns one (1) when the stream is stopped, zero (0) when - the stream is running or, a PaErrorCode (which are always negative) if - PortAudio is not initialized or an error is encountered. - - @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive -*/ -PaError Pa_IsStreamStopped( PaStream *stream ); - - -/** Determine whether the stream is active. - A stream is active after a successful call to Pa_StartStream(), until it - becomes inactive either as a result of a call to Pa_StopStream() or - Pa_AbortStream(), or as a result of a return value other than paContinue from - the stream callback. In the latter case, the stream is considered inactive - after the last buffer has finished playing. - - @return Returns one (1) when the stream is active (ie playing or recording - audio), zero (0) when not playing or, a PaErrorCode (which are always negative) - if PortAudio is not initialized or an error is encountered. - - @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped -*/ -PaError Pa_IsStreamActive( PaStream *stream ); - - - -/** A structure containing unchanging information about an open stream. - @see Pa_GetStreamInfo -*/ - -typedef struct PaStreamInfo -{ - /** this is struct version 1 */ - int structVersion; - - /** The input latency of the stream in seconds. This value provides the most - accurate estimate of input latency available to the implementation. It may - differ significantly from the suggestedLatency value passed to Pa_OpenStream(). - The value of this field will be zero (0.) for output-only streams. - @see PaTime - */ - PaTime inputLatency; - - /** The output latency of the stream in seconds. This value provides the most - accurate estimate of output latency available to the implementation. It may - differ significantly from the suggestedLatency value passed to Pa_OpenStream(). - The value of this field will be zero (0.) for input-only streams. - @see PaTime - */ - PaTime outputLatency; - - /** The sample rate of the stream in Hertz (samples per second). In cases - where the hardware sample rate is inaccurate and PortAudio is aware of it, - the value of this field may be different from the sampleRate parameter - passed to Pa_OpenStream(). If information about the actual hardware sample - rate is not available, this field will have the same value as the sampleRate - parameter passed to Pa_OpenStream(). - */ - double sampleRate; - -} PaStreamInfo; - - -/** Retrieve a pointer to a PaStreamInfo structure containing information - about the specified stream. - @return A pointer to an immutable PaStreamInfo structure. If the stream - parameter invalid, or an error is encountered, the function returns NULL. - - @param stream A pointer to an open stream previously created with Pa_OpenStream. - - @note PortAudio manages the memory referenced by the returned pointer, - the client must not manipulate or free the memory. The pointer is only - guaranteed to be valid until the specified stream is closed. - - @see PaStreamInfo -*/ -const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream ); - - -/** Determine the current time for the stream according to the same clock used - to generate buffer timestamps. This time may be used for syncronising other - events to the audio stream, for example synchronizing audio to MIDI. - - @return The stream's current time in seconds, or 0 if an error occurred. - - @see PaTime, PaStreamCallback -*/ -PaTime Pa_GetStreamTime( PaStream *stream ); - - -/** Retrieve CPU usage information for the specified stream. - The "CPU Load" is a fraction of total CPU time consumed by a callback stream's - audio processing routines including, but not limited to the client supplied - stream callback. This function does not work with blocking read/write streams. - - This function may be called from the stream callback function or the - application. - - @return - A floating point value, typically between 0.0 and 1.0, where 1.0 indicates - that the stream callback is consuming the maximum number of CPU cycles possible - to maintain real-time operation. A value of 0.5 would imply that PortAudio and - the stream callback was consuming roughly 50% of the available CPU time. The - return value may exceed 1.0. A value of 0.0 will always be returned for a - blocking read/write stream, or if an error occurrs. -*/ -double Pa_GetStreamCpuLoad( PaStream* stream ); - - -/** Read samples from an input stream. The function doesn't return until - the entire buffer has been filled - this may involve waiting for the operating - system to supply the data. - - @param stream A pointer to an open stream previously created with Pa_OpenStream. - - @param buffer A pointer to a buffer of sample frames. The buffer contains - samples in the format specified by the inputParameters->sampleFormat field - used to open the stream, and the number of channels specified by - inputParameters->numChannels. If non-interleaved samples were requested, - buffer is a pointer to the first element of an array of non-interleaved - buffer pointers, one for each channel. - - @param frames The number of frames to be read into buffer. This parameter - is not constrained to a specific range, however high performance applications - will want to match this parameter to the framesPerBuffer parameter used - when opening the stream. - - @return On success PaNoError will be returned, or PaInputOverflowed if input - data was discarded by PortAudio after the previous call and before this call. -*/ -PaError Pa_ReadStream( PaStream* stream, - void *buffer, - unsigned long frames ); - - -/** Write samples to an output stream. This function doesn't return until the - entire buffer has been consumed - this may involve waiting for the operating - system to consume the data. - - @param stream A pointer to an open stream previously created with Pa_OpenStream. - - @param buffer A pointer to a buffer of sample frames. The buffer contains - samples in the format specified by the outputParameters->sampleFormat field - used to open the stream, and the number of channels specified by - outputParameters->numChannels. If non-interleaved samples were requested, - buffer is a pointer to the first element of an array of non-interleaved - buffer pointers, one for each channel. - - @param frames The number of frames to be written from buffer. This parameter - is not constrained to a specific range, however high performance applications - will want to match this parameter to the framesPerBuffer parameter used - when opening the stream. - - @return On success PaNoError will be returned, or paOutputUnderflowed if - additional output data was inserted after the previous call and before this - call. -*/ -PaError Pa_WriteStream( PaStream* stream, - const void *buffer, - unsigned long frames ); - - -/** Retrieve the number of frames that can be read from the stream without - waiting. - - @return Returns a non-negative value representing the maximum number of frames - that can be read from the stream without blocking or busy waiting or, a - PaErrorCode (which are always negative) if PortAudio is not initialized or an - error is encountered. -*/ -signed long Pa_GetStreamReadAvailable( PaStream* stream ); - - -/** Retrieve the number of frames that can be written to the stream without - waiting. - - @return Returns a non-negative value representing the maximum number of frames - that can be written to the stream without blocking or busy waiting or, a - PaErrorCode (which are always negative) if PortAudio is not initialized or an - error is encountered. -*/ -signed long Pa_GetStreamWriteAvailable( PaStream* stream ); - - -/* Miscellaneous utilities */ - - -/** Retrieve the size of a given sample format in bytes. - - @return The size in bytes of a single sample in the specified format, - or paSampleFormatNotSupported if the format is not supported. -*/ -PaError Pa_GetSampleSize( PaSampleFormat format ); - - -/** Put the caller to sleep for at least 'msec' milliseconds. This function is - provided only as a convenience for authors of portable code (such as the tests - and examples in the PortAudio distribution.) - - The function may sleep longer than requested so don't rely on this for accurate - musical timing. -*/ -void Pa_Sleep( long msec ); - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* PORTAUDIO_H */ diff --git a/map65/set570.cpp b/map65/set570.cpp index ca9b4ef9e..b49d7f231 100644 --- a/map65/set570.cpp +++ b/map65/set570.cpp @@ -22,8 +22,7 @@ #include #endif -#include -//#include "/users/joe/linrad/3.37/usb.h" +#include #include #define USB_SUCCESS 0 @@ -48,21 +47,15 @@ int increment_freq; int retval = -1; int display_freq = -1; int delay; -usb_dev_handle *global_si570usb_handle = NULL; +static libusb_device_handle * global_si570usb_handle; -// ********sleep functions*************** -//use this function under LINUX -/* void si570_sleep(int us) { -usleep(us); -} -*/ - -//use this function under WINDOWS -void si570_sleep(int us) -{ - Sleep(us/1000); +#if defined (Q_OS_WIN) + ::Sleep (us / 1000); +#else + ::usleep (us); +#endif } double round(double x) @@ -78,11 +71,9 @@ double current_time(void) //for delay measurements return 0.000001*t.tv_usec+t.tv_sec; } -int usbGetStringAscii(usb_dev_handle *dev, int my_index, - int langid, char *buf, int buflen); -unsigned char Si570usbOpenDevice(usb_dev_handle **device, char *usbSerialID); +unsigned char Si570usbOpenDevice(libusb_device_handle **device, char *usbSerialID); void setLongWord( int value, char * bytes); -int setFreqByValue(usb_dev_handle * handle, double frequency); +int setFreqByValue(libusb_device_handle * handle, double frequency); void sweepa_freq(void); void sweepm_freq(void); @@ -105,111 +96,105 @@ int set570(double freq_MHz) return 0; } -int usbGetStringAscii(usb_dev_handle *dev, int my_index, - int langid, char *buf, int buflen) +unsigned char Si570usbOpenDevice (libusb_device_handle * * udh, char * usbSerialID) { - char buffer[256]; - int rval, i; - if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, - (USB_DT_STRING << 8) + my_index, langid, buffer, - sizeof(buffer), 1000)) < 0) return rval; - if(buffer[1] != USB_DT_STRING) return 0; - if((unsigned char)buffer[0] < rval) rval = (unsigned char)buffer[0]; - rval /= 2; -// lossy conversion to ISO Latin1 - for(i=1;i buflen) break; // destination buffer overflow - buf[i-1] = buffer[2 * i]; - if(buffer[2 * i + 1] != 0) buf[i-1] = '?'; // outside of ISO Latin1 range - } - buf[i-1] = 0; - return i-1; -} + // if (*udh) return USB_SUCCESS; // only scan USB devices 1st time -unsigned char Si570usbOpenDevice(usb_dev_handle **device, char *usbSerialID) -{ - struct usb_bus *bus; - struct usb_device *dev; - usb_dev_handle *handle = NULL; - unsigned char errorCode = USB_ERROR_NOTFOUND; - char string[256]; - int len; int vendor = USBDEV_SHARED_VENDOR; char *vendorName = (char *)VENDOR_NAME; int product = USBDEV_SHARED_PRODUCT; char *productName = (char *)PRODUCT_NAME; - char serialNumberString[20]; - static int didUsbInit = 0; - if(!didUsbInit) { - didUsbInit = 1; - usb_init(); - } - usb_find_busses(); - usb_find_devices(); - for(bus=usb_get_busses(); bus; bus=bus->next) { - for(dev=bus->devices; dev; dev=dev->next) { - if(dev->descriptor.idVendor == vendor && - dev->descriptor.idProduct == product) { - handle = usb_open(dev); // open the device in order to query strings - if(!handle) { - errorCode = USB_ERROR_ACCESS; - printf("si570.c: Warning: cannot open Si570-USB device:\n"); - printf("usb error message: %s\n",usb_strerror()); - continue; + libusb_device_handle * handle = nullptr; + unsigned char errorCode = USB_ERROR_NOTFOUND; + char buffer[256]; + int rc; + if ((rc = libusb_init (nullptr)) < 0) // init default context (safe to repeat) + { + printf ("usb initialization error message %s\n", libusb_error_name (rc)); + return errorCode = USB_ERROR_ACCESS; } - if(vendorName == NULL && productName == NULL) { //name does not matter - break; + + libusb_device * * device_list; + int device_count = libusb_get_device_list (nullptr, &device_list); + if (device_count < 0) + { + puts ("no usb devices"); + errorCode = USB_ERROR_NOTFOUND; } - // now check whether the names match - len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string)); - if(len < 0) { - errorCode = USB_ERROR_IO; - printf("si570.c: Warning: cannot query manufacturer for Si570-USB device:\n"); - printf("usb error message: %s\n",usb_strerror()); - } else { - errorCode = USB_ERROR_NOTFOUND; - //fprintf(stderr, "seen device from vendor ->%s<-\n", string); - if(strcmp(string, vendorName) == 0){ - len = usbGetStringAscii(handle, dev->descriptor.iProduct, - 0x0409, string, sizeof(string)); - if(len < 0) { - errorCode = USB_ERROR_IO; - printf("si570.c: Warning: cannot query product for Si570-USB device: \n"); - printf("usb error message: %s\n",usb_strerror()); - } else { - errorCode = USB_ERROR_NOTFOUND; - // fprintf(stderr, "seen product ->%s<-\n", string); - if(strcmp(string, productName) == 0) { - len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, - 0x0409, serialNumberString, sizeof(serialNumberString)); - if (len < 0) { - errorCode = USB_ERROR_IO; - printf("si570.c: Warning: cannot query serial number for Si570-USB device: \n"); - printf("usb error message: %s\n",usb_strerror()); - } else { - errorCode = USB_ERROR_NOTFOUND; - if ((usbSerialID == NULL) || - (strcmp(serialNumberString, usbSerialID) == 0)) { -// printf("\nOpen Si570 USB device: OK\n"); -// printf("usbSerialID : %s\n",serialNumberString); - break; - } + else + { + for (int i = 0; i < device_count; ++i) + { + libusb_device * device = device_list[i]; + libusb_device_descriptor descriptor; + if ((rc = libusb_get_device_descriptor (device, &descriptor)) < 0) + { + printf ("usb get devive descriptor error message %s\n", libusb_error_name (rc)); + errorCode = USB_ERROR_ACCESS; + continue; + } + if (vendor == descriptor.idVendor && product == descriptor.idProduct) + { + // now we must open the device to query strings + if ((rc = libusb_open (device, &handle)) < 0) + { + printf ("usb open device descriptor error message %s\n", libusb_error_name (rc)); + errorCode = USB_ERROR_ACCESS; + continue; + } + if (!vendorName && !productName) + { + break; // good to go + } + if (libusb_get_string_descriptor_ascii (handle, descriptor.iManufacturer + , reinterpret_cast (buffer), sizeof buffer) < 0) + { + printf ("usb get vendor name error message %s\n", libusb_error_name (rc)); + errorCode = USB_ERROR_IO; + } + else + { + if (!vendorName || !strcmp (buffer, vendorName)) + { + if (libusb_get_string_descriptor_ascii (handle, descriptor.iProduct + , reinterpret_cast (buffer), sizeof buffer) < 0) + { + printf ("usb get product name error message %s\n", libusb_error_name (rc)); + errorCode = USB_ERROR_IO; + } + else + { + if (!productName || !strcmp (buffer, productName)) + { + if (libusb_get_string_descriptor_ascii (handle, descriptor.iSerialNumber + , reinterpret_cast (buffer), sizeof buffer) < 0) + { + printf ("usb get serial number error message %s\n", libusb_error_name (rc)); + errorCode = USB_ERROR_IO; + } + else + { + if (!usbSerialID || !strcmp (buffer, usbSerialID)) + { + break; // good to go + } + } + } + } + } + } + libusb_close (handle); + handle = nullptr; + } } - } - } - } + libusb_free_device_list (device_list, 1); } - usb_close(handle); - handle = NULL; - } + if (handle) + { + errorCode = USB_SUCCESS; + *udh = handle; } - if(handle) break; - } - if(handle != NULL) { - errorCode = USB_SUCCESS; - *device = handle; - } return errorCode; } @@ -221,7 +206,7 @@ void setLongWord( int value, char * bytes) bytes[3] = ((value & 0xff000000) >> 24) & 0xff; } -int setFreqByValue(usb_dev_handle * handle, double frequency) +int setFreqByValue(libusb_device_handle * handle, double frequency) { // Windows Doc from PE0FKO: // @@ -236,7 +221,7 @@ int setFreqByValue(usb_dev_handle * handle, double frequency) // Default: None // // Parameters: -// requesttype: USB_ENDPOINT_OUT +// requesttype: LIBUSB_ENDPOINT_OUT // request: 0x32 // value: 0 // index: 0 @@ -264,14 +249,14 @@ int setFreqByValue(usb_dev_handle * handle, double frequency) err_cnt =0; set_again:; setLongWord(round(frequency * 2097152.0), buffer); // 2097152=2^21 - retval=usb_control_msg( - handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, - request, - value, - my_index, - buffer, - sizeof(buffer), - 5000); + retval = libusb_control_transfer ( + handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT, + request, + value, + my_index, + reinterpret_cast (buffer), + sizeof(buffer), + 5000); if (retval != 4) { err_cnt ++; if(err_cnt < MAX_USB_ERR_CNT) { @@ -279,7 +264,7 @@ int setFreqByValue(usb_dev_handle * handle, double frequency) goto set_again; } else { printf("Error when setting frequency, returncode=%i\n",retval); - printf("usb error message: %s\n", usb_strerror()); + printf("usb error message: %s\n", libusb_error_name (retval)); } } return retval; diff --git a/map65/signalmeter.cpp b/map65/signalmeter.cpp index 537b900f8..cf23079b1 100755 --- a/map65/signalmeter.cpp +++ b/map65/signalmeter.cpp @@ -29,7 +29,7 @@ SignalMeter::~SignalMeter() void SignalMeter::paintEvent( QPaintEvent * ) { QPainter p; - p.begin(this); + p.drawLine(22, 10, 22, 130); for ( int i = 0; i <= 60; i += 10 ) { diff --git a/map65/soundin.cpp b/map65/soundin.cpp index 77480cff8..bca728a4d 100644 --- a/map65/soundin.cpp +++ b/map65/soundin.cpp @@ -331,9 +331,7 @@ void SoundInThread::inputUDP() } // Set this socket's total buffer space for received UDP packets - int v=141600; - ::setsockopt(udpSocket->socketDescriptor(), SOL_SOCKET, SO_RCVBUF, - (char *)&v, sizeof(v)); + udpSocket->setSocketOption (QUdpSocket::ReceiveBufferSizeSocketOption, 141600); bool qe = quitExecution; struct linradBuffer { diff --git a/map65/usb.h b/map65/usb.h deleted file mode 100644 index 51c6a6556..000000000 --- a/map65/usb.h +++ /dev/null @@ -1,409 +0,0 @@ -#ifndef __USB_H__ -#define __USB_H__ - -#include -#include - -/* - * 'interface' is defined somewhere in the Windows header files. This macro - * is deleted here to avoid conflicts and compile errors. - */ - -#ifdef interface -#undef interface -#endif - -/* - * PATH_MAX from limits.h can't be used on Windows if the dll and - * import libraries are build/used by different compilers - */ - -#define LIBUSB_PATH_MAX 512 - - -/* - * USB spec information - * - * This is all stuff grabbed from various USB specs and is pretty much - * not subject to change - */ - -/* - * Device and/or Interface Class codes - */ -#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ -#define USB_CLASS_AUDIO 1 -#define USB_CLASS_COMM 2 -#define USB_CLASS_HID 3 -#define USB_CLASS_PRINTER 7 -#define USB_CLASS_MASS_STORAGE 8 -#define USB_CLASS_HUB 9 -#define USB_CLASS_DATA 10 -#define USB_CLASS_VENDOR_SPEC 0xff - -/* - * Descriptor types - */ -#define USB_DT_DEVICE 0x01 -#define USB_DT_CONFIG 0x02 -#define USB_DT_STRING 0x03 -#define USB_DT_INTERFACE 0x04 -#define USB_DT_ENDPOINT 0x05 - -#define USB_DT_HID 0x21 -#define USB_DT_REPORT 0x22 -#define USB_DT_PHYSICAL 0x23 -#define USB_DT_HUB 0x29 - -/* - * Descriptor sizes per descriptor type - */ -#define USB_DT_DEVICE_SIZE 18 -#define USB_DT_CONFIG_SIZE 9 -#define USB_DT_INTERFACE_SIZE 9 -#define USB_DT_ENDPOINT_SIZE 7 -#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ -#define USB_DT_HUB_NONVAR_SIZE 7 - - -/* ensure byte-packed structures */ -#include - - -/* All standard descriptors have these 2 fields in common */ -struct usb_descriptor_header -{ - unsigned char bLength; - unsigned char bDescriptorType; -}; - -/* String descriptor */ -struct usb_string_descriptor -{ - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short wData[1]; -}; - -/* HID descriptor */ -struct usb_hid_descriptor -{ - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short bcdHID; - unsigned char bCountryCode; - unsigned char bNumDescriptors; -}; - -/* Endpoint descriptor */ -#define USB_MAXENDPOINTS 32 -struct usb_endpoint_descriptor -{ - unsigned char bLength; - unsigned char bDescriptorType; - unsigned char bEndpointAddress; - unsigned char bmAttributes; - unsigned short wMaxPacketSize; - unsigned char bInterval; - unsigned char bRefresh; - unsigned char bSynchAddress; - - unsigned char *extra; /* Extra descriptors */ - int extralen; -}; - -#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ -#define USB_ENDPOINT_DIR_MASK 0x80 - -#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */ -#define USB_ENDPOINT_TYPE_CONTROL 0 -#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1 -#define USB_ENDPOINT_TYPE_BULK 2 -#define USB_ENDPOINT_TYPE_INTERRUPT 3 - -/* Interface descriptor */ -#define USB_MAXINTERFACES 32 -struct usb_interface_descriptor -{ - unsigned char bLength; - unsigned char bDescriptorType; - unsigned char bInterfaceNumber; - unsigned char bAlternateSetting; - unsigned char bNumEndpoints; - unsigned char bInterfaceClass; - unsigned char bInterfaceSubClass; - unsigned char bInterfaceProtocol; - unsigned char iInterface; - - struct usb_endpoint_descriptor *endpoint; - - unsigned char *extra; /* Extra descriptors */ - int extralen; -}; - -#define USB_MAXALTSETTING 128 /* Hard limit */ - -struct usb_interface -{ - struct usb_interface_descriptor *altsetting; - - int num_altsetting; -}; - -/* Configuration descriptor information.. */ -#define USB_MAXCONFIG 8 -struct usb_config_descriptor -{ - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short wTotalLength; - unsigned char bNumInterfaces; - unsigned char bConfigurationValue; - unsigned char iConfiguration; - unsigned char bmAttributes; - unsigned char MaxPower; - - struct usb_interface *interface; - - unsigned char *extra; /* Extra descriptors */ - int extralen; -}; - -/* Device descriptor */ -struct usb_device_descriptor -{ - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short bcdUSB; - unsigned char bDeviceClass; - unsigned char bDeviceSubClass; - unsigned char bDeviceProtocol; - unsigned char bMaxPacketSize0; - unsigned short idVendor; - unsigned short idProduct; - unsigned short bcdDevice; - unsigned char iManufacturer; - unsigned char iProduct; - unsigned char iSerialNumber; - unsigned char bNumConfigurations; -}; - -struct usb_ctrl_setup -{ - unsigned char bRequestType; - unsigned char bRequest; - unsigned short wValue; - unsigned short wIndex; - unsigned short wLength; -}; - -/* - * Standard requests - */ -#define USB_REQ_GET_STATUS 0x00 -#define USB_REQ_CLEAR_FEATURE 0x01 -/* 0x02 is reserved */ -#define USB_REQ_SET_FEATURE 0x03 -/* 0x04 is reserved */ -#define USB_REQ_SET_ADDRESS 0x05 -#define USB_REQ_GET_DESCRIPTOR 0x06 -#define USB_REQ_SET_DESCRIPTOR 0x07 -#define USB_REQ_GET_CONFIGURATION 0x08 -#define USB_REQ_SET_CONFIGURATION 0x09 -#define USB_REQ_GET_INTERFACE 0x0A -#define USB_REQ_SET_INTERFACE 0x0B -#define USB_REQ_SYNCH_FRAME 0x0C - -#define USB_TYPE_STANDARD (0x00 << 5) -#define USB_TYPE_CLASS (0x01 << 5) -#define USB_TYPE_VENDOR (0x02 << 5) -#define USB_TYPE_RESERVED (0x03 << 5) - -#define USB_RECIP_DEVICE 0x00 -#define USB_RECIP_INTERFACE 0x01 -#define USB_RECIP_ENDPOINT 0x02 -#define USB_RECIP_OTHER 0x03 - -/* - * Various libusb API related stuff - */ - -#define USB_ENDPOINT_IN 0x80 -#define USB_ENDPOINT_OUT 0x00 - -/* Error codes */ -#define USB_ERROR_BEGIN 500000 - -/* - * This is supposed to look weird. This file is generated from autoconf - * and I didn't want to make this too complicated. - */ -#define USB_LE16_TO_CPU(x) - -/* Data types */ -/* struct usb_device; */ -/* struct usb_bus; */ - -struct usb_device -{ - struct usb_device *next, *prev; - - char filename[LIBUSB_PATH_MAX]; - - struct usb_bus *bus; - - struct usb_device_descriptor descriptor; - struct usb_config_descriptor *config; - - void *dev; /* Darwin support */ - - unsigned char devnum; - - unsigned char num_children; - struct usb_device **children; -}; - -struct usb_bus -{ - struct usb_bus *next, *prev; - - char dirname[LIBUSB_PATH_MAX]; - - struct usb_device *devices; - unsigned long location; - - struct usb_device *root_dev; -}; - -/* Version information, Windows specific */ -struct usb_version -{ - struct - { - int major; - int minor; - int micro; - int nano; - } dll; - struct - { - int major; - int minor; - int micro; - int nano; - } driver; -}; - - -struct usb_dev_handle; -typedef struct usb_dev_handle usb_dev_handle; - -/* Variables */ -#ifndef __USB_C__ -#define usb_busses usb_get_busses() -#endif - - - -#include - - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Function prototypes */ - - /* usb.c */ - usb_dev_handle *usb_open(struct usb_device *dev); - int usb_close(usb_dev_handle *dev); - int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf, - size_t buflen); - int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf, - size_t buflen); - - /* descriptors.c */ - int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep, - unsigned char type, unsigned char index, - void *buf, int size); - int usb_get_descriptor(usb_dev_handle *udev, unsigned char type, - unsigned char index, void *buf, int size); - - /* .c */ - int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, - int value, int index, char *bytes, int size, - int timeout); - int usb_set_configuration(usb_dev_handle *dev, int configuration); - int usb_claim_interface(usb_dev_handle *dev, int interface); - int usb_release_interface(usb_dev_handle *dev, int interface); - int usb_set_altinterface(usb_dev_handle *dev, int alternate); - int usb_resetep(usb_dev_handle *dev, unsigned int ep); - int usb_clear_halt(usb_dev_handle *dev, unsigned int ep); - int usb_reset(usb_dev_handle *dev); - - char *usb_strerror(void); - - void usb_init(void); - void usb_set_debug(int level); - int usb_find_busses(void); - int usb_find_devices(void); - struct usb_device *usb_device(usb_dev_handle *dev); - struct usb_bus *usb_get_busses(void); - - - /* Windows specific functions */ - -#define LIBUSB_HAS_INSTALL_SERVICE_NP 1 - int usb_install_service_np(void); - void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - -#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1 - int usb_uninstall_service_np(void); - void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - -#define LIBUSB_HAS_INSTALL_DRIVER_NP 1 - int usb_install_driver_np(const char *inf_file); - void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - -#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1 - int usb_touch_inf_file_np(const char *inf_file); - void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - -#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1 - int usb_install_needs_restart_np(void); - - const struct usb_version *usb_get_version(void); - - int usb_isochronous_setup_async(usb_dev_handle *dev, void **context, - unsigned char ep, int pktsize); - int usb_bulk_setup_async(usb_dev_handle *dev, void **context, - unsigned char ep); - int usb_interrupt_setup_async(usb_dev_handle *dev, void **context, - unsigned char ep); - - int usb_submit_async(void *context, char *bytes, int size); - int usb_reap_async(void *context, int timeout); - int usb_reap_async_nocancel(void *context, int timeout); - int usb_cancel_async(void *context); - int usb_free_async(void **context); - - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_H__ */ - diff --git a/map65/widegraph.cpp b/map65/widegraph.cpp index e5e0f073a..ee60e6925 100644 --- a/map65/widegraph.cpp +++ b/map65/widegraph.cpp @@ -1,5 +1,4 @@ #include "widegraph.h" -#include #include "ui_widegraph.h" #define NFFT 32768 @@ -381,9 +380,9 @@ void WideGraph::tx570() void WideGraph::updateFreqLabel() { - double rxFreq = floor (ui->widePlot->rxFreq () * 1e3) * 1e3; - double txFreq = floor (ui->widePlot->txFreq() * 1e3) * 1e3; - ui->labFreq->setText (QString {"Rx: %1\n%2"}.arg (rxFreq, 7, 'f', 3).arg (txFreq, 7, 'f', 3)); + auto rxFreq = QString {"%1"}.arg (ui->widePlot->rxFreq (), 10, 'f', 6).insert (7, '.'); + auto txFreq = QString {"%1"}.arg (ui->widePlot->txFreq (), 10, 'f', 6).insert (7, '.'); + ui->labFreq->setText (QString {"Rx: %1\nTx: %2"}.arg (rxFreq, txFreq)); } void WideGraph::enableSetRxHardware(bool b)