Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Signal Generator Part 3 (Show waveforms in textArea using Math.sin(angle) )  RSS feed

 
Stephen Carter
Greenhorn
Posts: 22
Chrome Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the final part of my program. Now I have to generate the appropriate waveform according to what button I press and generate the sound while the waveform is cycling.
For example, I input the sound frequency, the time it plays sound and waveform, and the volume, and then select Sawtooth. This will generate the sound and sawtooth waves.
The problem is that I do not know which class that I should edit the math function to and the proper syntax (Math.sin();). I know that (angle) should be inputted as radians, but how to find the right radians for different shapes?
The oscillate class was provided (coded) by my Professor, and I was told to edit it so that it would work with my siggen class.
I would appreciate if you could help me figure this out. Also, should the function be in a loop together with timer?

siggen



oscillate

 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephen Carter wrote:. . .
That code is incorrect, not only because of poor indentation (don't try to cram ten lines of code into one line), but because you have empty catch statements which will obscure any Exceptions from you. Also please post the code again with underling to show which parts of the code are part of the if statements. You can't use underlining in code tags, so you will need plain text.
 
Stephen Carter
Greenhorn
Posts: 22
Chrome Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Stephen Carter wrote:. . .
That code is incorrect, not only because of poor indentation (don't try to cram ten lines of code into one line), but because you have empty catch statements which will obscure any Exceptions from you. Also please post the code again with underling to show which parts of the code are part of the if statements. You can't use underlining in code tags, so you will need plain text.


Sorry, but I have edited the code since the last post. Also, I am using vim, as per my instructor. IDE's are forbidden in his classroom, so I have no underlining.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your instructor is right to stop you using IDEs. But you can underline on the Ranch. Simply use the u button above. Show us where the if starts and ends.
 
Stephen Carter
Greenhorn
Posts: 22
Chrome Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Your instructor is right to stop you using IDEs. But you can underline on the Ranch. Simply use the 'u' button above. Show us where the if starts and ends.

I am sorry. I am not sure what you are asking for. But I did clean up the code.

 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephen Carter wrote:. . .
I am sorry. I am not sure what you are asking for. But I did clean up the code.
. . .
That code is not a clean up.
  • 1: You still have the empty catch.
  • 2: You still have the catch on one line. You cannot expect to read code unless you format it properly.
  • 3: You have one additional pair of {} per option over and above what you had before. That is a major semantic change.
  • This is the new code:-Please copy and paste that code into your next post, and put a comment // end if at the end of the if block Similarly please copy and paste the following code and add a similar // end if comment to it. At the end of the if. What follows is what you had before:-
    if (w.equals("Square")) try { o.generate(fre,len,amp, "Square"); } catch (Exception lue) { } textArea.setText("Square\n");

    You should avoid catching plain simple Exception, if you can catch a more specific type of Exception. I am please to see you have changed from Exception to a more specific type and I can now see why you called it lue.
    You do realise that you have five lines of repeated code in the block I quoted (old version)? You do realise you can reduce that to one very simply. And you should reduce that.

    Please indent your code correctly. You should never have a } at the end of a full line (except for a small array initialser). You are making life difficult for yourself because your incorrect indentation is hiding things from you.
     
    Campbell Ritchie
    Sheriff
    Posts: 53750
    127
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Stephen Carter wrote:. . .
    Avoid System.exit. If you have any threads running, you will terminate them all, and may end up with corrupted records. Use an exit method.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!