How to generate a tone

This should be a trivial question but I can't seem to find the answer!
I want to generate a tone of a given frequency for a specified duration. For example, I want to generate a tone of 440Hz for 0.6 of a second.
In the documents I can see on the Apple developer site, I can see how to do this if I have a whole set of .WAV files which I can then read, edit and play, but this seems to be way off the mark for what I want to do.
In Garageband I can get a tone for as long as I press a "keyboard" key, so there must be some way to actually generate the tone but I don't seem to be able to find this information within all of the other audio capabilities.
Thanks
Susan

You could always fill some audio queue buffers with the appropriate sine wave (math function sin(), or complex recursion or precalculated table lookup for much better performance). Increment each sample's phase by 2piF/Fs, and multiply the resulting sinewave by a volume level, for a duration*Fs number of samples. Remember to save the current phase between queue buffers and to maybe ramp down the level of the first and last few sinewave cycles to prevent clicks and pops.
.

Similar Messages

  • How to use PXIe-5673e to continously generate dual-tone waveform?

    Hi, everyone!
     I want to use PXIe-5673e to continously generate dual-tone waveform, and I have see some examples of RFSG, but I still don't know which one to use, can someone help me? 
    Thank you very much!!

    See if this example VI helps
    Ches this one too

  • Example: Code to generate audio tone

    This code shows how to generate and play a simple sinusoidal audio tone using the javax.sound.sampled API (see the generateTone() method for the details).
    This can be particularly useful for checking a PCs sound system, as well as testing/debugging other sound related applications (such as an audio trace app.).
    The latest version should be available at..
    <http://www.physci.org/test/sound/Tone.java>
    You can launch it directly from..
    <http://www.physci.org/test/oscilloscope/tone.jar>
    Hoping it may be of use.
    package org.physci.sound;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.LineUnavailableException;
    import java.awt.BorderLayout;
    import java.awt.Toolkit;
    import java.awt.Image;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JSlider;
    import javax.swing.JCheckBox;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.border.TitledBorder;
    import java.net.URL;
    Audio tone generator, using the Java sampled sound API.
    @author andrew Thompson
    @version 2007/12/6
    public class Tone extends JFrame {
      static AudioFormat af;
      static SourceDataLine sdl;
      public Tone() {
        super("Audio Tone");
        // Use current OS look and feel.
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                SwingUtilities.updateComponentTreeUI(this);
            } catch (Exception e) {
                System.err.println("Internal Look And Feel Setting Error.");
                System.err.println(e);
        JPanel pMain=new JPanel(new BorderLayout());
        final JSlider sTone=new JSlider(JSlider.VERTICAL,200,2000,441);
        sTone.setPaintLabels(true);
        sTone.setPaintTicks(true);
        sTone.setMajorTickSpacing(200);
        sTone.setMinorTickSpacing(100);
        sTone.setToolTipText(
          "Tone (in Hertz or cycles per second - middle C is 441 Hz)");
        sTone.setBorder(new TitledBorder("Frequency"));
        pMain.add(sTone,BorderLayout.CENTER);
        final JSlider sDuration=new JSlider(JSlider.VERTICAL,0,2000,1000);
        sDuration.setPaintLabels(true);
        sDuration.setPaintTicks(true);
        sDuration.setMajorTickSpacing(200);
        sDuration.setMinorTickSpacing(100);
        sDuration.setToolTipText("Duration in milliseconds");
        sDuration.setBorder(new TitledBorder("Length"));
        pMain.add(sDuration,BorderLayout.EAST);
        final JSlider sVolume=new JSlider(JSlider.VERTICAL,0,100,20);
        sVolume.setPaintLabels(true);
        sVolume.setPaintTicks(true);
        sVolume.setSnapToTicks(false);
        sVolume.setMajorTickSpacing(20);
        sVolume.setMinorTickSpacing(10);
        sVolume.setToolTipText("Volume 0 - none, 100 - full");
        sVolume.setBorder(new TitledBorder("Volume"));
        pMain.add(sVolume,BorderLayout.WEST);
        final JCheckBox cbHarmonic  = new JCheckBox( "Add Harmonic", true );
        cbHarmonic.setToolTipText("..else pure sine tone");
        JButton bGenerate = new JButton("Generate Tone");
        bGenerate.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              try{
                generateTone(sTone.getValue(),
                  sDuration.getValue(),
                  (int)(sVolume.getValue()*1.28),
                  cbHarmonic.isSelected());
              }catch(LineUnavailableException lue){
                System.out.println(lue);
        JPanel pNorth = new JPanel(new BorderLayout());
        pNorth.add(bGenerate,BorderLayout.WEST);
        pNorth.add( cbHarmonic, BorderLayout.EAST );
        pMain.add(pNorth, BorderLayout.NORTH);
        pMain.setBorder( new javax.swing.border.EmptyBorder(5,3,5,3) );
        getContentPane().add(pMain);
        pack();
        setLocation(0,20);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        String address = "/image/tone32x32.png";
        URL url = getClass().getResource(address);
        if (url!=null) {
          Image icon = Toolkit.getDefaultToolkit().getImage(url);
          setIconImage(icon);
      /** Generates a tone.
      @param hz Base frequency (neglecting harmonic) of the tone in cycles per second
      @param msecs The number of milliseconds to play the tone.
      @param volume Volume, form 0 (mute) to 100 (max).
      @param addHarmonic Whether to add an harmonic, one octave up. */
      public static void generateTone(int hz,int msecs, int volume, boolean addHarmonic)
        throws LineUnavailableException {
        float frequency = 44100;
        byte[] buf;
        AudioFormat af;
        if (addHarmonic) {
          buf = new byte[2];
          af = new AudioFormat(frequency,8,2,true,false);
        } else {
          buf = new byte[1];
          af = new AudioFormat(frequency,8,1,true,false);
        SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
        sdl = AudioSystem.getSourceDataLine(af);
        sdl.open(af);
        sdl.start();
        for(int i=0; i<msecs*frequency/1000; i++){
          double angle = i/(frequency/hz)*2.0*Math.PI;
          buf[0]=(byte)(Math.sin(angle)*volume);
          if(addHarmonic) {
            double angle2 = (i)/(frequency/hz)*2.0*Math.PI;
            buf[1]=(byte)(Math.sin(2*angle2)*volume*0.6);
            sdl.write(buf,0,2);
          } else {
            sdl.write(buf,0,1);
        sdl.drain();
        sdl.stop();
        sdl.close();
      public static void main(String[] args){
        Runnable r = new Runnable() {
          public void run() {
            Tone t = new Tone();
            t.setVisible(true);
        SwingUtilities.invokeLater(r);
    }

    JLudwig wrote:
    Any reason why you call getSourceDataLine() twice? ..Oh wait, I know this one (..snaps fingers. yes) it is because I am a mor0n, and forgot the class level (static) attribute declared earlier in the source when I (re)declared the local attribute and called getSourceDatLine (which was redundant, given the next line, which as you point out also called getSourceDataLine).
    There are (at least) two ways to correct this problem.
    1) Remove the class level attribute and the second call.
    2) Remove the local attribute as well as the first call (all on the same code line).
    Method 1 makes more sense, unless you intend to refactor the code to only instantiate a single SDL for however many times the user presses (what was it? Oh yeah..) 'Generate Tone'.
    My 'excuse' for my odd programming is that this was 'hacked down' from a longer program to form an SSCCE. I should have paid more attention to the fine details (and perhaps run a lint checker on it).
    Thanks for pointing that out. I guess from the fact you spotted it, that you have already corrected the problem. That you thought to report it, gives me confidence that you 'will go far (and be well thought of, besides)' in the open source community.
    ..This is quite handy, thank you.You're welcome. Thanks for letting us know about the error (OK - the pointless redundancy). Thanks to your report, other people who see this code later, will not have to wonder what (the heck) I was thinking when I did that.
    Another thing I noted, now I run the source on a 400MHz laptop (it's hard times, here) is that the logic could be improved. At the speeds that my laptop can feed data into the SDL, the sound that comes out the speakers approximates the sound of flatulence (with embedded static, as a free bonus!).
    Edit 1: Changed one descriptive word so that it might get by the net-nanny.
    Edited by: AndrewThompson64 on Mar 27, 2008 11:09 PM

  • How to generate jasper report in pdf format using swing

    hi all,
    im new to swing and jasper.. can anybody provide me some example on how to generate the jasper report in pdf format? i will call the reportManager from sessionBean.. below is my code:
    1)delegate:
    public GenerateReportDto generateIntoPdfReport(String fileName, String outputFileName, Map parameters){
    GenerateReportDto generateReportDto = getAuditTrailServiceRemote().generateIntoPdfReport(fileName, outputFileName, parameters);
    return generateReportDto;
    2)sessionBean:
    public GenerateReportDto generateIntoPdfReport(String fileName, String outputFileName, Map parameters){
    //Map parameters = new HashMap();
    ReportManager reportManager = new ReportManager();
    3)ReportManager()
    public void generateIntoPdfReport(String fileName, String outputFileName, Map parameters) {
              Connection conn = null;
              try {
                   conn = dataSource.getConnection();
                   //Generate the report to bytes
                   File reportFile = new File(fileName);               
                   byte[] bytes =
                        JasperRunManager.runReportToPdf(
                             reportFile.getPath(),
                             parameters,
                             conn
              //conn.close();
              //Write the bytes to a file
              ByteBuffer buf = ByteBuffer.wrap(bytes);
              File file = new File(outputFileName);
              // (if the file exists)
              boolean append = false;
              // Create a writable file channel
              FileChannel wChannel = new FileOutputStream(file, append).getChannel();
              // Write the ByteBuffer contents; the bytes between the ByteBuffer's
              // position and the limit is written to the file
              wChannel.write(buf);
              // Close the file
              wChannel.close();
              } finally {
                   if (conn != null) {
    conn.close();
    Any help would be highly appreciated. Thanks in advance

    Hi ,
    One 'simple' way is by using the DBMS_SCHEDULER db package and the procedure CREATE_JOB(....) using as job_type the value 'EXECUTABLE'...
    Read for further info in 'PL/SQL Packages and Types Reference'.
    If you have access to OEM ... you can configure this there using wizard.....
    Other way is to use the External Procedure call capabiblity of Oracle DB Server...:
    http://www.oracle.com/pls/db102/ranked?word=external+procedure+call&remark=federated_search
    My greetings,
    Sim

  • Best Practices:: How to generate XML file from a ResultSet

    Hi all,
    Could someone please suggest the best practices of how to generate an XML file from a resultset? I am developing a web application in Java with Oracle database and one of my tasks is to generate an XML file when the user, for example, click a "download as XML" button on the JSP. The application is basically like an Order with line items. I am using Struts and my first thought has been to have an action class which will extend struts's DownloadAction and through StAX's Iterator API to create an XML file. I intend to have a POJO which will have properties of all columns of my order and line items tables so that for each order I get all line items and:
    1. Write order details then
    2. Through an iterator write line items of that order to an XML file.
    I will greatly appreciate for comments or suggestions on the best way to do this through any pointers on the Web.
    alex

    Use a OracleWebRowSet in which an XML representation of the result set may be obtained.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/oracle10g/webrowset/Readme.html
    http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/jcrowset.htm

  • How to Generate Statistic Graph in Report??

    Hi, i am developing an questionnaire program together with 19 question... i am able to get value for each value..
    Now my problem is how to generate a statistic graph whenever user can check their report ??
    Can anyone help?? Thank you very much......
    from bscs

    The easy way is to use your values to set the width or height of an image dynamically in HTML, but you can only do bar charts using this method.
    For real reports and measures have a look at
    http://www.jfree.org/jfreechart/index.php
    http://www.jfree.org/jfreereport/index.php

  • How to generate multiple output pdf's from one oracle reports

    how to generate multiple output pdf's from one oracle reports.
    I have a report where I have to generate more than one output files from the same report based on a parameter.
    Each output file is for each parameter.
    Is this possible in oracle reports, is so how ?

    You can better post your question in the reports forum instead of this pl/sql forum.

  • How to generate a row in report to compute total?

    Hi:
    I need help to generate a report. In an accounting report, I need to make sum for each client regarding outstanding balance. The format of report is following:
    invoice#, invoice date, invoice amount, paid amount paid date, write off, outstanding balance
    Client Name: Baker Express / Debtor Name: Kurt Weiss inc.
    137308001, 04/18/2012, 438.07, 537.07, 06/05/2012, , (99)
    137308002, 04/18/2012, 100, 90, 06/05/2012, 10,
    client Total: total payment:627.07, total outstanding balance: (99)
    another client and debtor pair
    My question is how to generate total payment and total outstanding balancefor every pair of client and debtor. And there are multiple pairs. I tried to use group by, but how can I display every invoice tuple as well in the report?
    Any help would be appreciated.
    Sam

    One method would be to use ROLLUP in your SQL
    http://www.oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets.php

  • How to generate a report direct in PDF with oracle developer 6i

    hi all
    Please help me about this issue.
    THAT How to generate a report directly in PDF using oracle developer 6i.
    Regards
    Yousuf Ahmed Siddiqui

    Hi,
    You can create the Report directly in PDF by setting some of the Report Parameters
    i.e. DESTYPE, DESNAME AND DESFORMAT as follows before calling the Report.
    DECLARE
         PL_ID          PARAMLIST;
         PL_NAME     VARCHAR2(10) := 'param_list';
    BEGIN     
         PL_ID := GET_PARAMETER_LIST (PL_NAME);
         IF NOT ID_NULL (PL_ID) THEN
                  Destroy_Parameter_List(PL_ID);
         END IF;
         PL_ID := Create_Parameter_List(PL_NAME);
         Add_Parameter (PL_ID, 'DESTYPE', TEXT_PARAMETER, 'FILE');
         Add_Parameter (PL_ID, 'DESNAME', TEXT_PARAMETER, 'c:\test.pdf');
         Add_Parameter (PL_ID, 'DESFORMAT', TEXT_PARAMETER, 'PDF');
            RUN_PRODUCT (REPORTS, 'REPORT_NAME', ASYNCHRONOUS, RUNTIME, FILESYSTEM, PL_ID, NULL);
    END;Hope this helps.
    Best Regards
    Arif Khadas
    Edited by: Arif Khadas on Apr 22, 2010 9:24 AM

  • How to generate pdf report in swing

    Hello,
    can you help me?
    i want to generate pdf report in my swing based project but i don't know about any idea of this report generating
    procedure . Please help me.

    shesh_07 wrote:
    Hello,
    can you help me?Can you help yourself? Two suggestions I have for posting to a technical forum are:
    1) Add an upper case letter to the start of each sentence. This helps the reader to scan the text quickly, looking for the important parts. It also helps to dispel the impression that the writer is just lazy.
    2) Try to do some research on your own, summarise it and state any conclusions you have reached. Ask a specific question and generally, try not to sound so pathetic.
    i want to generate pdf report ..Search for [Java PDF|http://lmgtfy.com/?q=java+pdf] *(<- link).*
    Figure how to generate a PDF report in a class used from the command line, then..
    ..in my swing based project .....wrap a GUI around that class. For details on the latter, see the [Swing tutorial|http://java.sun.com/docs/books/tutorial/uiswing/] *(<- link).*
    ..but i don't know about any idea of this report generating
    procedure . Please help me.Please help yourself.

  • How to generate interactive report in alv

    hi,
      how to generate interactive report in alv,for this what are the requirements,
    give me one sample report.
                                                 thankyou.

    Hi,
    Chk these helpful links..
    ALV
    http://www.geocities.com/mpioud/Abap_programs.html
    http://www.sapdevelopment.co.uk/reporting/reportinghome.htm
    Simple ALV report
    http://www.sapgenie.com/abap/controls/alvgrid.htm
    http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
    ALV
    1. Please give me general info on ALV.
    http://www.sapfans.com/forums/viewtopic.php?t=58286
    http://www.sapfans.com/forums/viewtopic.php?t=76490
    http://www.sapfans.com/forums/viewtopic.php?t=20591
    http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
    2. How do I program double click in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=11601
    http://www.sapfans.com/forums/viewtopic.php?t=23010
    3. How do I add subtotals (I have problem to add them)...
    http://www.sapfans.com/forums/viewtopic.php?t=20386
    http://www.sapfans.com/forums/viewtopic.php?t=85191
    http://www.sapfans.com/forums/viewtopic.php?t=88401
    http://www.sapfans.com/forums/viewtopic.php?t=17335
    4. How to add list heading like top-of-page in ABAP lists?
    http://www.sapfans.com/forums/viewtopic.php?t=58775
    http://www.sapfans.com/forums/viewtopic.php?t=60550
    http://www.sapfans.com/forums/viewtopic.php?t=16629
    5. How to print page number / total number of pages X/XX in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
    6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
    http://www.sapfans.com/forums/viewtopic.php?t=64320
    http://www.sapfans.com/forums/viewtopic.php?t=44477
    7. How can I set the cell color in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=52107
    8. How do I print a logo/graphics in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=81149
    http://www.sapfans.com/forums/viewtopic.php?t=35498
    http://www.sapfans.com/forums/viewtopic.php?t=5013
    9. How do I create and use input-enabled fields in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=84933
    http://www.sapfans.com/forums/viewtopic.php?t=69878
    10. How can I use ALV for reports that are going to be run in background?
    http://www.sapfans.com/forums/viewtopic.php?t=83243
    http://www.sapfans.com/forums/viewtopic.php?t=19224
    11. How can I display an icon in ALV? (Common requirement is traffic light icon).
    http://www.sapfans.com/forums/viewtopic.php?t=79424
    http://www.sapfans.com/forums/viewtopic.php?t=24512
    12. How can I display a checkbox in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=88376
    http://www.sapfans.com/forums/viewtopic.php?t=40968
    http://www.sapfans.com/forums/viewtopic.php?t=6919
    Go thru these programs they may help u to try on some hands on
    ALV Demo program
    BCALV_DEMO_HTML
    BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode
    BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode
    BCALV_GRID_DEMO Simple ALV Control Call Demo Program
    BCALV_TREE_DEMO Demo for ALV tree control
    BCALV_TREE_SIMPLE_DEMO
    BC_ALV_DEMO_HTML_D0100
    Regards
    Anversha

  • How to generate a report in pdf from a stored proc

    Hi, i need guidance on how to generate a report in pdf from an oracle stored proc.
    The environment is oracle 10gas + 10gdb.
    On a specific event, a PL/SQL stored procedure is called to do some processing and at the end of the processing to generate report which has to be sent to the printer (and optionally previewed by the user).
    Can anyone assist me with this?

    Hi ,
    One 'simple' way is by using the DBMS_SCHEDULER db package and the procedure CREATE_JOB(....) using as job_type the value 'EXECUTABLE'...
    Read for further info in 'PL/SQL Packages and Types Reference'.
    If you have access to OEM ... you can configure this there using wizard.....
    Other way is to use the External Procedure call capabiblity of Oracle DB Server...:
    http://www.oracle.com/pls/db102/ranked?word=external+procedure+call&remark=federated_search
    My greetings,
    Sim

  • How to generate a report in Excel with multiple sheets using oracle10g

    Hi,
    I need a small help...
    we are using Oracle 10g...
    How to generate a report in Excel with multiple sheets.
    Thanks in advance.
    Regards,
    Ram

    Thanks Denis.
    I am using Oraclereports 10g version, i know desformat=spreadsheet will create single worksheet with out pagination, but my requirment is like the output should be generated in .xls file, and each worksheet will have both data and graphs.
    rdf paperlayout format will not workout for generating multiple worksheets.
    Is it possible to create multiple worksheets by using .jsp weblayout(web source) in oracle reports10g. If possible please provide me some examples
    Regards,
    Ram

  • How to generate my report in HTML format

    Hi
    I am using Forms and reports 6i . How to generate a report in Html format.
    Please explain what are the option available in reports and the way to do
    thanks in advance
    prasanth a.s.

    *specify  desformat=html  in cmd line
    refer
    * Forms Reports integration 6i
    http://otn.oracle.com/products/forms/pdf/277282.pdf
    [    All Docs for all versions    ]
    http://otn.oracle.com/documentation/reports.html
    [     Publishing reports to web  - 10G  ]
    http://download.oracle.com/docs/html/B10314_01/toc.htm (html)
    http://download.oracle.com/docs/pdf/B10314_01.pdf (pdf)
    [   Building reports  - 10G ]
    http://download.oracle.com/docs/pdf/B10602_01.pdf (pdf)
    http://download.oracle.com/docs/html/B10602_01/toc.htm (html)
    [   Forms Reports Integration whitepaper  9i ]
    http://otn.oracle.com/products/forms/pdf/frm9isrw9i.pdf
    ---------------------------------------------------------------------------------

  • How to generate a report based on account description

    Hi Experts,
    How to generate the report based on account description, that means
    i want to generate a report on G/L account and which account numbers are having 'CASH' description.
    for Ex: G/L a/c no: 25010026-Cash and Bank balance(des)
    G/L a/c no: 101000-Cash-freight
    like this.
    please help to do this,
    good answer will be appreciated with points,
    Thanks in advance
    Venkat

    Hi shana,
    my requirement is
    I have G/L account numbers, that account numbers having some descriptions, in these some descriptions are belongs to cash transactions, i want to generate the report on these cash transactions, and the report is " G/L account, debit cash, credit cash, balance".
    is it possible or not,
    thanks in advance,
    Venkat

Maybe you are looking for

  • MS Access 2013 Web App script error when viewing datasheet view

    Hi--in MS Access 2013 on my PC (Win 7 64), whenever I hit VIEW+DATASHEET, I get a script error. I have tried multiple solutions, including one posted here to delete all of the files in the DatabaseCache folder. Here's a screenshot of the error I get:

  • Netweaver Developer in different language

    Hello I would like to know how I can change the language of the Netweaver Developer to anything other then english. Are there language files that I can exchange somewhere? Has anyone thought of developers who would like a developing  environment in t

  • Select List based on other select List

    Hi I have 2 select lists when a selection is made in one I want the second list to be limited but when nothing is selected in the first list I want the second list to display all. Apolgies if this is really a plsql thing . Heres what I have so far if

  • Weblogic 11g reports url

    I have just setup a new dev environment for a development team on Weblogic 11g (10.3.2.0) with forms and reports. In iAS, I could run a report with the url: http://myserver/reports/rwservlet?server=rep_server&report=myreport.RDF&userid=user1/password

  • Unsupported key or value

    Hi, I'm getting the following error when I try to retreive an object from the cache: 11:10:47,835 ERROR [STDERR] java.lang.IllegalArgumentException: Unsupported key or value: Key=1391631, Value=PartyImpl[PartyImpl[PartyImpl[objectId=61 380,entityId=6