MainWindow.java. Page 1

Similar documents
Explaining & Accessing the SPDX License List

HALCoGen TMS570LS31x Help: example_sci_uart_9600.c

User Manual for Video Codec

Open Source Used In TSP

MUMPS IO Documentation

IETF TRUST. Legal Provisions Relating to IETF Documents. Approved November 6, Effective Date: November 10, 2008

Watch 4 Size v1.0 User Guide By LeeLu Soft 2013

CSCE Inspection Activity Name(s):

Distinction Import Module User Guide. DISTINCTION.CO.UK

Intel Stress Bitstreams and Encoder (Intel SBE) 2017 AVS2 Release Notes (Version 2.3)

ColdFusion Builder 3.2 Third Party Software Notices and/or Additional Terms and Conditions

IETF TRUST. Legal Provisions Relating to IETF Documents. February 12, Effective Date: February 15, 2009

calio / form-input-nginx-module

Table of Contents Overview...2 Selecting Post-Processing: ColorMap...3 Overview of Options Copyright, license, warranty/disclaimer...

pyserial-asyncio Documentation

About This Guide. and with the Cisco Nexus 1010 Virtual Services Appliance: N1K-C1010

Package fst. December 18, 2017

System Log NextAge Consulting Pete Halsted

Copyright PFU LIMITED 2016

Open Source Used In c1101 and c1109 Cisco IOS XE Fuji

MagicInfo Express Content Creator

PageScope Box Operator Ver. 3.2 User s Guide

ProgressBar Abstract

NemHandel Referenceklient 2.3.1

Packet Trace Guide. Packet Trace Guide. Technical Note

An Easy Way to Split a SAS Data Set into Unique and Non-Unique Row Subsets Thomas E. Billings, MUFG Union Bank, N.A., San Francisco, California

NemHandel Referenceklient 2.3.0

FLAMEBOSS 300 MANUAL

iphone/ipad Connection Manual

Preface. Audience. Cisco IOS Software Documentation. Organization

Graphic Inspector 2 User Guide

The Cron service allows you to register STAF commands that will be executed at a specified time interval(s).

Ecma International Policy on Submission, Inclusion and Licensing of Software

ANZ TRANSACTIVE MOBILE for ipad

Spout to NDI. Convert between Spout and Newtek NDI sources. Using the Newtek NDI SDK. Version 2.

Static analysis for quality mobile applications

Copyright PFU LIMITED

This file includes important notes on this product and also the additional information not included in the manuals.

AccuTerm 7 Internet Edition Connection Designer Help. Copyright Schellenbach & Assoc., Inc.

cs50.c /**************************************************************************** * CS50 Library 6 *

Avaya VPN Client Software Release 10.05_100

Fujitsu ScandAll PRO V2.1.5 README

FLAME BOSS 200V2 & 300 MANUAL. Version 2.6 Download latest at FlameBoss.com/manuals

Package fst. June 7, 2018

@list = bsd_glob('*.[ch]'); $homedir = bsd_glob('~gnat', GLOB_TILDE GLOB_ERR);

sptrans Documentation

Documentation Roadmap for Cisco Prime LAN Management Solution 4.2

GoldSim License Portal A User s Guide for Managing Your GoldSim Licenses

Open Source Used In Cisco Configuration Professional for Catalyst 1.0

Installation. List Wrangler - Mailing List Manager for GTK+ Part I. 1 Requirements. By Frank Cox. September 3,

Data Deduplication Metadata Extension

iwrite technical manual iwrite authors and contributors Revision: 0.00 (Draft/WIP)

APPLICATION NOTE. Atmel AT03261: SAM D20 System Interrupt Driver (SYSTEM INTERRUPT) SAM D20 System Interrupt Driver (SYSTEM INTERRUPT)

Ecma International Policy on Submission, Inclusion and Licensing of Software


Open Source and Standards: A Proposal for Collaboration

Small Logger File System

Anybus Wireless Bridge Ethernet Bluetooth Access Point Product Guide

openresty / array-var-nginx-module

JD Edwards EnterpriseOne 8.12 Standalone Client Installation Guide. for the Oracle Application Server

LabVIEW Driver. User guide Version

DAP Controller FCO

License, Rules, and Application Form

Grouper UI csrf xsrf prevention

User Guide. Calibrated Software, Inc.

Copyright 2010 by Microtek International, Inc. Trademarks. Important. All rights reserved.

This file includes important notes on this product and also the additional information not included in the manuals.

JPdfBookmarks Manual. by Flaviano Petrocchi

Installing AudioLinux (Alternative way with GUI)

HYDROOBJECTS VERSION 1.1

SNP Launchpad. Version: December SNP Schneider-Neureither & Partner AG

NTLM NTLM. Feature Description

RAVENNA-2-SAP Converter Installation + Operation Guide

TWAIN driver User s Guide

Definiens. Image Miner bit and 64-bit Edition. Release Notes

User Manual. Date Aug 30, Enertrax DAS Download Client

HYDRODESKTOP VERSION 1.4 QUICK START GUIDE

Dr. K. Y. Srinivasan. Jason Goldschmidt. Technical Lead NetApp Principal Architect Microsoft Corp.

T-Invoicer User Guide

Enterprise Payment Solutions. Scanner Installation April EPS Scanner Installation: Quick Start for Remote Deposit Complete TM

Technics Audio Player User Guide

Taking the LPC800 into the delta quadrant :)

Splunk. Splunk. Deployment Guide

Note: The version the Event service must be 1.10 or later (but less than 3.0.0).

Definiens. Image Miner bit and 64-bit Editions. Release Notes

Migration Tool. Migration Tool (Beta) Technical Note

Internet Connection Guide

Adobe Connect. Adobe Connect. Deployment Guide

HYDRODESKTOP VERSION 1.1 BETA QUICK START GUIDE

KEMP Driver for Red Hat OpenStack. KEMP LBaaS Red Hat OpenStack Driver. Installation Guide

PTZ Control Center Operations Manual

US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

Request for Comments: Oversi O. Nicklass, Ed. RADVISION May Definitions of Textual Conventions for Pseudowire (PW) Management

SAM4 Reset Controller (RSTC)

Denkh XML Reporter. Web Based Report Generation Software. Written By Scott Auge Amduus Information Works, Inc.

Pulse Check User Guide and Technical Guide. Quick Start Framework. Version Name: Winter 16 Version Number: 1.5 Date:

GoldSim License Server Activation Utility Installation and Basic Use

Nova Talk USER GUIDE. Nova Talk for Android. Revision: 1.3. Nova Talk_User_Guide_Android.docx

Business Rules NextAge Consulting Pete Halsted

HIS document 2 Loading Observations Data with the ODDataLoader (version 1.0)

Transcription:

/ This project is a demo showing a sound card selector and tester. The UI would look nice and work better, but I've decided that's outside the scope of this demo. Code from this demo will eventually be reused in a Java version of my ClipBoard reader. NOTE: It seems to take a moment for a digital sound (S/PDIF) to start playing. NOTE: In this demo, two sound cards with the same name are not supported. Only the top one in the combo box can be selected. (Whichever the computer sees first.) NOTE: This demo needs DirectX on Windows and SDL on Linux since the demo accesses the hardware directly. NOTE: I can't test on macos since I don't have macos. Project copyright follows Copyright (c) 2017, James Marchant All rights reserved. Redistribution and use in source and binary forms, with or without Page 1

modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. package info.jamiemarchant.test.ui; Page 2

import java.awt.eventqueue; public class MainWindow { private JFrame _jfrmsoundcardselector; private JButton _jbtntest; private boolean _startingup = true; private Thread _audiothread; private WhiteNoiseRunnable _wnrunnable; private JComboBox<String> _jcbsoundcardnames; private ArrayList<Line> _alllines = new ArrayList<Line>(); / Launch the application. public static void main(string[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MainWindow window = new MainWindow(); window._jfrmsoundcardselector.setvisible(true); catch (Exception e) { e.printstacktrace(); Page 3

); / Create the application. public MainWindow() { initialize(); / Initialize the contents of the frame. private void initialize() { _wnrunnable = new WhiteNoiseRunnable(); _audiothread = null; _jfrmsoundcardselector = new JFrame(); _jfrmsoundcardselector.settitle("sound Card Selector"); _jfrmsoundcardselector.setbounds(100, 100, 954, 97); _jfrmsoundcardselector.setdefaultcloseoperation(jframe.exit_on_close); JButton _btnok = new JButton("Ok"); _btnok.addactionlistener(new ActionListener() { public void actionperformed(actionevent arg0) { JOptionPane.showMessageDialog(_btnOk,"Ok hit. In a larger program " + " the results would be saved."); Page 4

); System.exit(1); _jfrmsoundcardselector.getcontentpane().add(_btnok, BorderLayout.EAST); _jcbsoundcardnames = new JComboBox<String>(); _jcbsoundcardnames.additemlistener(new ItemListener() { public void itemstatechanged(itemevent arg0) { if(!_startingup){ stopsound(); ); _jcbsoundcardnames.addpropertychangelistener(new PropertyChangeListener() { public void propertychange(propertychangeevent arg0) { // No longer used; wrong event. //This part might be needed for the designer. ); _jfrmsoundcardselector.getcontentpane().add(_jcbsoundcardnames, BorderLayout.CENTER); // Initialize the mixer. Info[] infoaboutmixers = AudioSystem.getMixerInfo(); Page 5

for(javax.sound.sampled.mixer.info infoaboutmixer : infoaboutmixers){ Mixer amixer = AudioSystem.getMixer(infoAboutMixer); try { amixer.open(); javax.sound.sampled.line.info[] infolines = amixer.getsourcelineinfo(); System.out.println(infolines.length); int portcounter = 1; for(javax.sound.sampled.line.info infoline : infolines){ Line line = amixer.getline(infoline); String niceoutput = ""; //niceoutput += infoaboutmixer.getvendor(); niceoutput += infoaboutmixer.getname(); niceoutput += infoaboutmixer.getdescription(); niceoutput += ": port#" + portcounter; / To be meaningful name is needed for Linux, but description is needed for Windows. As I said at the top, I can't test macos. portcounter++; // Only add "SourceDataLines". At the moment, // we only handle these objects. if(line instanceof SourceDataLine){ _alllines.add(line);// all lines for all mixers. _jcbsoundcardnames.additem(niceoutput); Page 6

/ Right now, this is limited to sound devices(all speakers, S/PDIF, HDMI). / In the future, I want it to work on a port level (front speakers of Sound Blaster Live) / Just a reminder that descriptions come from the OS and how they are named are beyond my control. amixer.close(); catch (LineUnavailableException e) { System.err.println(e.getMessage()); JOptionPane.showMessageDialog(_jfrmSoundCardSelector, "The sound card '" + amixer.getmixerinfo().getdescription() + "' Could not be accessed, is it busy?", "warning", JOptionPane.WARNING_MESSAGE); _jbtntest = new JButton("Test"); _jbtntest.addactionlistener(new ActionListener() { public void actionperformed(actionevent arg0) { Page 7

if(_jbtntest.gettext().equals("stop")){ stopsound(); else{ int selectedindex = _jcbsoundcardnames.getselectedindex(); Line theline = _alllines.get(selectedindex); System.out.println(theLine.getClass().getName()); _wnrunnable.setdateline((sourcedataline) theline); _wnrunnable.setkeeplooping(true); _audiothread = new Thread(_wnrunnable); // You can't restart a thread once it's stopped, // so we need to make a new thread. _audiothread.start(); _jbtntest.settext("stop"); ); _jfrmsoundcardselector.getcontentpane().add(_jbtntest, BorderLayout.WEST); _startingup = false; protected void stopsound() { if(_audiothread == null){ return; // No sound has started. Page 8

System.out.println("Stop sound called"); _jbtntest.settext("test"); _wnrunnable.setkeeplooping(false); System.out.println("Joing the endless loop"); try { _audiothread.join();// Wait for the thread to stop. catch (InterruptedException e) { System.err.println("Failed to naturally stop thread"); int selectedindex = _jcbsoundcardnames.getselectedindex(); _alllines.get(selectedindex).close(); / The above may cause issues if a sound card is disconnected, but that's outside the scope of this demo. The order of items in the list will remain the same, but they may not be alphabetical. Sorting them is outside the scope of this demo. //theline.close(); JOptionPane.showMessageDialog(_jbtnTest, "The program has encountered an" + " error and must quit."); // Probably safer than stopping threads. I need to make sure resources are free. System.exit(1); Page 9

WhiteNoiseRunnable.java / Copyright (c) 2017, James Marchant All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. package info.jamiemarchant.test.threading; import java.nio.bytebuffer; Page 1

WhiteNoiseRunnable.java import java.util.random; import javax.sound.sampled.audioformat; import javax.sound.sampled.lineunavailableexception; import javax.sound.sampled.sourcedataline; import javax.swing.joptionpane; / Runnable that creates white noise @author Jamie Marchant public class WhiteNoiseRunnable implements Runnable { private volatile boolean _keeplooping = true; private volatile ByteBuffer _buffer; private volatile SourceDataLine _line = null; public void setsourcedatalineandport(sourcedataline lvar){ _line = lvar; public void setdateline(sourcedataline theline){ _line = theline; / The packet size used to generate the noise. Page 2

WhiteNoiseRunnable.java // Note sure why this is 5000, since it was not explained in the // sample. final static public int PACKET_SIZE = 5000; final static public int SAMPLE_SIZE = 2; @Override / Creates white noise on the audio mixer. @throws NullPointerException if an audio line has not been set. public void run() { if(_line!= null){ // code from: // https://stackoverflow.com/questions/26963342/generating-colors-of-noise-in-java AudioFormat format = new AudioFormat(44100, 16, 1, true, true); //DataLine.Info info = new DataLine.Info(SourceDataLine.class, format, PACKET_SIZE 2); try { _line.open(format); _line.start(); _buffer = ByteBuffer.allocate(PACKET_SIZE); // NOTE: New IO thing, so Java 7? catch (LineUnavailableException e) { // Must be caught here but that's ok. System.err.println(e.getMessage()); JOptionPane.showMessageDialog(null, "Can't open audio device, is it busy?"); return; Page 3

WhiteNoiseRunnable.java else{ throw new NullPointerException("Line to use is now null"); Random random = new Random(); while(_keeplooping){ _buffer.clear(); for (int i=0; i < PACKET_SIZE /SAMPLE_SIZE; i++) { _buffer.putshort((short) (random.nextgaussian() Short.MAX_VALUE)); _line.write(_buffer.array(), 0, _buffer.position()); _line.stop(); _line.close(); / Sets the value that keeps the thread running. Do this and call "join" when you want to stop the thread. @param var - a true or false value, you probably want to set it false. public void setkeeplooping(boolean var){ _keeplooping = var; Page 4