Forum: Mikrocontroller und Digitale Elektronik Atmega8 Bascom "Sound"-Befehl


von Florian H. (florian_h14)


Angehängte Dateien:

Lesenswert?

Hallo Technikfaszinierte und Tüftler,
Ich bin hier neu im Forum und habe mich dazu durchgerungen mal einen 
Beitrag zu verfassen. Im Allgemeinen will ich nur kurz auf mein Programm 
eingehen: Der Note2µC-Converter.
Ich hatte folgendes Problem: Ich war dabei die Titelmelodie von einem 
meiner Lieblingsspiele abzutippem bis ich feststellen musste, dass das 
rumschauen in der Tabelle der Frequenzen,Perioden und Pulse verdammt 
nervig ist und zudem auch noch Zeit frisst. So hab ich mir die Mühe 
gemacht eine kleine Java-Anwendung zu schreiben die aus den "normalen" 
Noten den Bascom-Befehl zaubert. Die Syntax ist so:

     (Vorzeichen)+Notenbezeichnung+Oktave
      Länge

Als Vorzeichen wird "#" verwendet und die Notenbezeichnungen gehen von 
"C" bis "B"(Alle groß geschrieben). Die Oktaven reichen von 1-3.
Bei der Länge gibt es die Besonderheit, dass man eine Dezimalzahl 
angibt, die Längen sind 1(1/1) 0,5(1/2) 0,25(1/4) 0,125(1/8) 
0,0625(1/16).

Ein Beispiel:
Man nehme ein Ais(#A) in der 3. Oktave für eine halbe Note lang dann 
würde man eingeben "#A3" "0.5"

Wichtig ist noch, dass man bei der Länge einen Punkt macht und kein 
Komma, da Java sonst zickt.
Ich hoffe ich konnte ein paar 8-Bit-Fetischisten ein wenig arbeit 
ersparen, schönen Abend noch
"Anercomp" Flo

von D. V. (mazze69)


Lesenswert?

Ohne Sourcecode wird hier wohl niemand deine EXE anfassen wollen.
Also, poste den Sourcecode, wenn du Hilfe erwartest.

von Kindergärtner (Gast)


Lesenswert?

Bascom ist also so schlecht dass man ein extra Java Programm braucht um 
Code zu generieren? (nicht nur) in C könnte man deinen Eingabe-String 
einfach direkt auf den Controller speichern und dort interpretieren; in 
C++ könnte man den Compiler den String auch noch automatisch 
"komprimieren"(packen) lassen. Und das alles ohne Java...

von Ronny S. (phoenix-0815)


Lesenswert?

D. V. schrieb:
> Ohne Sourcecode wird hier wohl niemand deine EXE anfassen wollen.
> Also, poste den Sourcecode, wenn du Hilfe erwartest.

Hy,
 das scheint doch keine Anfrage nach einer Hilfe zu sein.
Das wird wohl ein April Scherz sein.

Gruß

von Ronny S. (phoenix-0815)


Lesenswert?

Kindergärtner schrieb:
> Bascom ist also so schlecht dass man ein extra Java Programm braucht um
> Code zu generieren?

Hy Kindergärtner,
könntest Du mal bitte deinen Post hier in Basic generieren damit auch 
die unwissenden dein Leid teilen können, das Du mit Basic hast.

Gruß

von Schuster (Gast)


Lesenswert?

Der Kindergärtner sollte bei seinem Leisten, alias Kindgarten-Umfeld, 
bleiben. Er hat offensichtlich nicht verstanden, das ein Compiler-Basic 
ausführbaren Maschinencode erzeugt, der nicht im µC erst platz- und 
zeitraubend gespeichert und interpretiert werden muss.

Und eine Hochsprache wie Java zu benutzen, um den Befehlsumfang eines 
Compiler-Dialekts zu erweitern, hat schonmal rein garnix mit der 
allgemeinen Leistungsfähigkeit des Compilers als solchem zu tun.

Hauptsache in Sachen Midweek-Crisis ein wenig Überdruck ablassen. Keine 
Ahnung von der Sache, und das dann auch noch frühmorgens gleich 
lautstark kundtun.... :-D

von Kindergärtner (Gast)


Lesenswert?

Schuster schrieb:
> Der Kindergärtner sollte bei seinem Leisten, alias
> Kindgarten-Umfeld,
> bleiben.
Deswegen bin ich doch hier.
> Er hat offensichtlich nicht verstanden, das ein Compiler-Basic
> ausführbaren Maschinencode erzeugt, der nicht im µC erst platz- und
> zeitraubend gespeichert und interpretiert werden muss.
Doch gewiss; bloß was hat das damit zu tun?
> Und eine Hochsprache wie Java zu benutzen, um den Befehlsumfang eines
> Compiler-Dialekts zu erweitern, hat schonmal rein garnix mit der
> allgemeinen Leistungsfähigkeit des Compilers als solchem zu tun.
Dann eben mit der Sprache.
> Hauptsache in Sachen Midweek-Crisis ein wenig Überdruck ablassen. Keine
> Ahnung von der Sache, und das dann auch noch frühmorgens gleich
> lautstark kundtun.... :-D
Das behauptet ein Bascom-User... Ich wette jeder einzelne generierte 
Bascom-"Sound" Befehl ist größer als 4 Bytes (allein schon da die 
AVR-Befehle >= 2 Bytes groß sind), sodass es sich schon lohnen würde die 
Daten einfach in einen String zu packen, ala "#F14bH18" für 
(Fis-1.Oktave-1/4, b-1.Oktabe-1/8) und den im Programm durchzulaufen und 
die entsprechende Aktion durchzuführen. Das "Interpretieren" eines so 
einfachen Formats dürfte ja nur minimal Rechenzeit beanspruchen. In 
Bascom scheint das ja nicht zu gehen - sonst wäre dieses Java-Programm 
nicht nötig - in C(++) hingegen schon...

von Paul B. (paul_baumann)


Lesenswert?

Florian schrabte:
>Ich bin hier neu im Forum und habe mich dazu durchgerungen mal einen
>Beitrag zu verfassen.

Na, das habt ihr ja prima hingekriegt, ihr Helden!
:-((

Der Mann ist das erste Mal hier, stellt ein Programm zur Verfügung und
wird zum Dank "Volley genommen".

So ein Empfang freut doch jeden Menschen...

MfG Paul

von Snoopy (Gast)


Lesenswert?

Kindergärtner schrieb:
> die entsprechende Aktion durchzuführen. Das "Interpretieren" eines so
> einfachen Formats ...

Könnte es sein, das du "parsen" meinst?

von Karl H. (kbuchegg)


Lesenswert?

'parsen' ist ein großes Wort für ein paar Fallunterscheidungen und ein 
bißchen rechnen. 'interpretieren' trifft es schon besser.

: Bearbeitet durch User
von Florian H. (florian_h14)


Lesenswert?

Paul Baumann schrieb:
>
> Na, das habt ihr ja prima hingekriegt, ihr Helden!
> :-((
>
> Der Mann ist das erste Mal hier, stellt ein Programm zur Verfügung und
> wird zum Dank "Volley genommen".
>
> So ein Empfang freut doch jeden Menschen...
>
> MfG Paul

Vielen Dank, ich dachte schon ich verliere meinen Glauben an die 
Menschheit :) und bevor hier das Battle C++ VS BASIC noch weiter geht 
könnten wirs dabei belassen, dass manche EINSTEIGER mit BASIC eben gut 
zurechtkommen und nur zu faul sind die ganze Zeit lange Befehle zu 
tippen??? Ich hab jetzt ein halbes Jahr Java in der Schule gehabt und 
wollte eigentlich nur mal einen winzigen Beitrag zum Forum liefern. Aber 
vorallem wollte ich mir das Gesuche in der Notentabelle sparen, dafür 
jetzt mal eben so C oder C++ zu lernen wäre übertrieben meiner Meinung 
nach.

Und hier einmal für alle "Das-war-ein-April-Scherz"-Leute der 
Sourcecode:
1
 
2
package UI;
3
4
public class Start {
5
6
  @SuppressWarnings("deprecation")
7
  public static void main(String[] args) {
8
    AppWindow theAppWindow = new AppWindow();
9
    theAppWindow.setBounds(10, 10, 420, 180);
10
    theAppWindow.show();
11
  }
12
}
13
14
15
package UI;
16
17
import java.awt.Toolkit;
18
import java.awt.datatransfer.StringSelection;
19
import java.awt.event.ActionEvent;
20
import java.awt.event.ActionListener;
21
import java.awt.event.WindowEvent;
22
import java.awt.event.WindowListener;
23
24
import javax.swing.JButton;
25
import javax.swing.JFrame;
26
import javax.swing.JLabel;
27
import javax.swing.JTextField;
28
29
import App.Converter;
30
31
public class AppWindow extends JFrame {
32
33
  private static final long serialVersionUID = 1L;
34
  JTextField _inputpNote;
35
    JTextField _inputpDuration;
36
    JLabel _note;
37
    JLabel _duration;
38
    JLabel _outputCommand;
39
    JLabel _info;
40
41
  JButton    button_convert;
42
  JButton    button_copy2clipboard;
43
  Converter noteconverter = new Converter();
44
45
46
  public AppWindow() {
47
    this.getContentPane().setLayout(null);
48
49
    this.initWindow();
50
51
    this.addWindowListener(new WindowListener() {
52
53
      public void windowClosed(WindowEvent arg0) {
54
55
56
      }
57
58
      public void windowActivated(WindowEvent e) {
59
60
61
      }
62
63
      public void windowClosing(WindowEvent e) {
64
        System.exit(0);
65
      }
66
67
      public void windowDeactivated(WindowEvent e) {
68
69
70
      }
71
72
      public void windowDeiconified(WindowEvent e) {
73
74
75
      }
76
77
      public void windowIconified(WindowEvent e) {
78
79
80
      }
81
82
      public void windowOpened(WindowEvent e) {
83
84
85
      }
86
87
88
89
    });
90
91
  }
92
93
  protected void initWindow(){
94
    _inputpNote = new JTextField("Note");
95
    _inputpDuration = new JTextField("Länge");
96
    
97
    _note = new JLabel();
98
        _duration = new JLabel();
99
        _outputCommand = new JLabel("Befehl");
100
        _info = new JLabel("Syntax: (Vorzeichen+)Großbuchtstabe+Oktave");
101
102
    button_convert = new JButton("C0NV3RT");
103
    button_copy2clipboard = new JButton("COPY");
104
105
    button_convert.addActionListener(new ActionListener() {
106
107
      public void actionPerformed(ActionEvent arg0) {
108
        
109
        String pNote = _inputpNote.getText();
110
        double pDuration = Double.valueOf(_inputpDuration.getText());
111
        noteconverter.setNote(pNote);
112
        noteconverter.setDuration(pDuration);
113
        String command = noteconverter.convert();
114
        _outputCommand.setText(command);
115
        
116
        }
117
      
118
      });
119
    
120
      button_copy2clipboard.addActionListener(new ActionListener() {
121
122
        public void actionPerformed(ActionEvent arg0) {
123
          _outputCommand.setText("                                ");
124
          _outputCommand.setText(noteconverter.convert());
125
              Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
126
                      new StringSelection(noteconverter.convert()), null);  
127
        }
128
      });
129
130
      _inputpNote.setBounds(180,10,100,25);
131
      _inputpDuration.setBounds(180,40,100,25);
132
133
      button_convert.setBounds(100,110,100,30);
134
      button_copy2clipboard.setBounds(250,110,100,30);
135
    
136
      _outputCommand.setBounds(180,70,180,30);
137
      _info.setBounds(10,85,340,30);
138
139
    this.getContentPane().add(_inputpNote);
140
    this.getContentPane().add(_inputpDuration);
141
    this.getContentPane().add(button_convert);
142
    this.getContentPane().add(button_copy2clipboard);
143
    this.getContentPane().add(_outputCommand);
144
    this.getContentPane().add(_info);
145
146
147
    this.pack();
148
  }
149
}
150
151
package App;
152
153
public class Converter {
154
  private String note;
155
  private int duration;
156
  private int pulse;
157
  private int period;
158
  
159
  public Converter(){
160
    
161
  }
162
  
163
  public void setNote(String pNote){
164
    this.note = pNote;
165
  }
166
  
167
  public String getNote(){
168
    return this.note;
169
  }
170
  
171
  public int getPulse() {
172
    return pulse;
173
  }
174
175
  public void setPulse(int pPulse) {
176
    pulse = pPulse;
177
  }
178
179
  public int getPeriod() {
180
    return period;
181
  }
182
183
  public void setPeriod(int pPeriod) {
184
    period = pPeriod;
185
  }
186
  
187
  public double getDuration() {
188
    return duration;
189
  }
190
191
  public void setDuration(double tempDuration) {
192
    tempDuration = tempDuration * 10000;
193
    this.duration = (int) tempDuration;
194
  }
195
  
196
  public String convert(){
197
    String uC_Command = "Sound Speaker , ";
198
    
199
    //'===============================================================================
200
    //' C1 |  261,63 |  2548 |    523   |    262   |    131   |    65    |     33    |
201
    //'Cis1|  277,18 |  2405 |    554   |    277   |    139   |    69    |     35    |
202
    //' D1 |  293,66 |  2270 |    587   |    294   |    147   |    73    |     37    |
203
    //'Dis1|  311,13 |  2143 |    622   |    311   |    156   |    78    |     39    |
204
    //' E1 |  329,63 |  2022 |    659   |    330   |    165   |    82    |     41    |
205
    //' F1 |  349,23 |  1909 |    698   |    349   |    175   |    87    |     44    |
206
    //'Fis1|  369,99 |  1802 |    740   |    370   |    185   |    92    |     46    |
207
    //' G1 |  392,00 |  1701 |    784   |    392   |    196   |    98    |     49    |
208
    //'Gis1|  415,30 |  1605 |    831   |    415   |    208   |   104    |     52    |
209
    //' A1 |  440,00 |  1515 |    880   |    440   |    220   |   110    |     55    |
210
    //'Ais1|  466,16 |  1430 |    932   |    466   |    233   |   117    |     58    |
211
    //' B1 |  493,88 |  1350 |    988   |    494   |    247   |   124    |     62    |
212
    //'===============================================================================
213
    //' C2 |  523,25 |  1274 |   1047   |    523   |    262   |   131    |     65    |
214
    //'Cis2|  554,36 |  1203 |   1109   |    554   |    277   |   139    |     69    |
215
    //' D2 |  587,32 |  1135 |   1175   |    587   |    294   |   147    |     73    |
216
    //'Dis2|  622,26 |  1071 |   1245   |    622   |    311   |   156    |     78    |
217
    //' E2 |  659,26 |  1011 |   1319   |    659   |    330   |   165    |     82    |
218
    //' F2 |  698,46 |   954 |   1397   |    698   |    349   |   175    |     87    |
219
    //'Fis2|  739,98 |   901 |   1480   |    740   |    370   |   185    |     92    |
220
    //' G2 |  784,00 |   850 |   1568   |    784   |    392   |   196    |     98    |
221
    //'Gis2|  830,60 |   803 |   1661   |    831   |    415   |   208    |    104    |
222
    //' A2 |  880,00 |   758 |   1720   |    880   |    440   |   220    |    110    |
223
    //'Ais2|  932,32 |   715 |   1865   |    932   |    466   |   233    |    117    |
224
    //' B2 |  987,75 |   675 |   1976   |    988   |    494   |   247    |    124    |
225
    //'===============================================================================
226
    //' C3 | 1046,50 |   637 |   2093   |   1047   |    523   |   262    |    131    |
227
    //'Cis3| 1108,70 |   601 |   2218   |   1109   |    554   |   277    |    139    |
228
    //' D3 | 1174,60 |   566 |   2350   |   1175   |    587   |   294    |    147    |
229
    //'Dis3| 1244,50 |   536 |   2490   |   1245   |    622   |   311    |    156    |
230
    //' E3 | 1318,50 |   483 |   2638   |   1319   |    659   |   330    |    165    |
231
    //' F3 | 1396,90 |   477 |   2794   |   1397   |    698   |   349    |    175    |
232
    //'Fis3| 1480,00 |   450 |   2960   |   1480   |    740   |   370    |    185    |
233
    //' G3 | 1568,00 |   425 |   3136   |   1568   |    784   |   392    |    196    |
234
    //'Gis3| 1661,20 |   401 |   3322   |   1661   |    831   |   415    |    208    |
235
    //' A3 | 1720,00 |   388 |   3440   |   1720   |    880   |   440    |    220    |
236
    //'Ais3| 1864,60 |   358 |   3730   |   1865   |    932   |   466    |    233    |
237
    //' B3 | 1975,50 |   337 |   3952   |   1976   |    988   |   494    |    247    |
238
    //'===============================================================================
239
    
240
    if (note.equals("C1")){
241
      period = 2548;
242
      if(duration == 10000){
243
        pulse = 523;}
244
      else if(duration == 5000){
245
        pulse = 262;
246
        }
247
      else if(duration == 2500){
248
        pulse = 131;
249
        }
250
      else if(duration == 1250){
251
        pulse = 65;
252
        }
253
      else if(duration == 625){
254
        pulse = 33;
255
        }
256
      else{
257
        uC_Command = "Unzulässige Werte";
258
        }
259
      }  
260
    
261
    else if(note.equals("#C1")){
262
      period = 2405;
263
      if(duration == 10000){
264
        pulse = 554;}
265
      else if(duration == 5000){
266
        pulse = 277;
267
        }
268
      else if(duration == 2500){
269
        pulse = 139;
270
        }
271
      else if(duration == 1250){
272
        pulse = 69;
273
        }
274
      else if(duration == 625){
275
        pulse = 35;
276
        }
277
      else{
278
        uC_Command = "Unzulässige Werte";
279
        }
280
    }
281
      
282
    
283
    else if (note.equals("D1")){
284
      period = 2270;
285
      if(duration == 10000){
286
        pulse = 587;}
287
      else if(duration == 5000){
288
        pulse = 294;
289
        }
290
      else if(duration == 2500){
291
        pulse = 147;
292
        }
293
      else if(duration == 1250){
294
        pulse = 73;
295
        }
296
      else if(duration == 625){
297
        pulse = 37;
298
        }
299
      else{
300
        uC_Command = "Unzulässige Werte";
301
        }
302
      }
303
    
304
    else if (note.equals("#D1")){
305
      period = 2143;
306
      if(duration == 10000){
307
        pulse = 622;}
308
      else if(duration == 5000){
309
        pulse = 311;
310
        }
311
      else if(duration == 2500){
312
        pulse = 156;
313
        }
314
      else if(duration == 1250){
315
        pulse = 78;
316
        }
317
      else if(duration == 625){
318
        pulse = 39;
319
        }
320
      else{
321
        uC_Command = "Unzulässige Werte";
322
        }
323
      }
324
    
325
    else if (note.equals("E1")){
326
      period = 2022;
327
      if(duration == 10000){
328
        pulse = 659;}
329
      else if(duration == 5000){
330
        pulse = 330;
331
        }
332
      else if(duration == 2500){
333
        pulse = 165;
334
        }
335
      else if(duration == 1250){
336
        pulse = 82;
337
        }
338
      else if(duration == 625){
339
        pulse = 41;
340
        }
341
      else{
342
        uC_Command = "Unzulässige Werte";
343
        }
344
      }
345
    
346
    else if (note.equals("F1")){
347
      period = 1909;
348
      if(duration == 10000){
349
        pulse = 698;}
350
      else if(duration == 5000){
351
        pulse = 349;
352
        }
353
      else if(duration == 2500){
354
        pulse = 175;
355
        }
356
      else if(duration == 1250){
357
        pulse = 87;
358
        }
359
      else if(duration == 625){
360
        pulse = 44;
361
        }
362
      else{
363
        uC_Command = "Unzulässige Werte";
364
        }
365
      }
366
    
367
    else if (note.equals("#F1")){
368
      period = 1802;
369
    if(duration == 10000){
370
      pulse = 740;}
371
    else if(duration == 5000){
372
      pulse = 370;
373
      }
374
    else if(duration == 2500){
375
      pulse = 185;
376
      }
377
    else if(duration == 1250){
378
      pulse = 92;
379
      }
380
    else if(duration == 625){
381
      pulse = 46;
382
      }
383
    else{
384
      uC_Command = "Unzulässige Werte";
385
      }
386
    
387
    }
388
    
389
    else if (note.equals("G1")){
390
      period = 1701;
391
    if(duration == 10000){
392
      pulse = 784;}
393
    else if(duration == 5000){
394
      pulse = 392;
395
      }
396
    else if(duration == 2500){
397
      pulse = 196;
398
      }
399
    else if(duration == 1250){
400
      pulse = 98;
401
      }
402
    else if(duration == 625){
403
      pulse = 49;
404
      }
405
    else{
406
      uC_Command = "Unzulässige Werte";
407
      }
408
    
409
    }
410
      
411
    else if (note.equals("#G1")){
412
        period = 1605;
413
      if(duration == 10000){
414
        pulse = 831;}
415
      else if(duration == 5000){
416
        pulse = 415;
417
        }
418
      else if(duration == 2500){
419
        pulse = 208;
420
        }
421
      else if(duration == 1250){
422
        pulse = 104;
423
        }
424
      else if(duration == 625){
425
        pulse = 52;
426
        }
427
      else{
428
        uC_Command = "Unzulässige Werte";
429
        }
430
      
431
      }
432
    
433
    else if (note.equals("A1")){
434
      period = 1515;
435
      if(duration == 10000){
436
        pulse = 880;}
437
      else if(duration == 5000){
438
        pulse = 440;
439
        }
440
      else if(duration == 2500){
441
        pulse = 220;
442
        }
443
      else if(duration == 1250){
444
        pulse = 110;
445
        }
446
      else if(duration == 625){
447
        pulse = 55;
448
        }
449
      else{
450
        uC_Command = "Unzulässige Werte";
451
        }
452
    }
453
      
454
    else if (note.equals("#A1")){
455
      period = 1430;
456
      if(duration == 10000){
457
        pulse = 932;}
458
      else if(duration == 5000){
459
        pulse = 466;
460
        }
461
      else if(duration == 2500){
462
        pulse = 233;
463
        }
464
      else if(duration == 1250){
465
        pulse = 117;
466
        }
467
      else if(duration == 625){
468
        pulse = 58;
469
        }
470
      else{
471
        uC_Command = "Unzulässige Werte";
472
        }
473
    }
474
      
475
    else if (note.equals("B1")){
476
      period = 1350;
477
      if(duration == 10000){
478
        pulse = 988;}
479
      else if(duration == 5000){
480
        pulse = 494;
481
        }
482
      else if(duration == 2500){
483
        pulse = 247;
484
        }
485
      else if(duration == 1250){
486
        pulse = 124;
487
        }
488
      else if(duration == 625){
489
        pulse = 62;
490
        }
491
      else{
492
        uC_Command = "Unzulässige Werte";
493
        }
494
    }
495
      
496
    else if (note.equals("C2")){
497
      period = 1274;
498
      if(duration == 10000){
499
        pulse = 1047;}
500
      else if(duration == 5000){
501
        pulse = 523;
502
        }
503
      else if(duration == 2500){
504
        pulse = 262;
505
        }
506
      else if(duration == 1250){
507
        pulse = 131;
508
        }
509
      else if(duration == 625){
510
        pulse = 65;
511
        }
512
      else{
513
        uC_Command = "Unzulässige Werte";
514
        }
515
    }
516
      
517
    else if (note.equals("#C2")){
518
      period = 1203;
519
      if(duration == 10000){
520
        pulse = 1109;}
521
      else if(duration == 5000){
522
        pulse = 554;
523
        }
524
      else if(duration == 2500){
525
        pulse = 277;
526
        }
527
      else if(duration == 1250){
528
        pulse = 139;
529
        }
530
      else if(duration == 625){
531
        pulse = 69;
532
        }
533
      else{
534
        uC_Command = "Unzulässige Werte";
535
        }
536
    }
537
      
538
    else if (note.equals("D2")){
539
      period = 1135;
540
      if(duration == 10000){
541
        pulse = 1175;}
542
      else if(duration == 5000){
543
        pulse = 587;
544
        }
545
      else if(duration == 2500){
546
        pulse = 294;
547
        }
548
      else if(duration == 1250){
549
        pulse = 147;
550
        }
551
      else if(duration == 625){
552
        pulse = 73;
553
        }
554
      else{
555
        uC_Command = "Unzulässige Werte";
556
        }
557
    }
558
      
559
    else if (note.equals("#D2")){
560
      period = 1071;
561
      if(duration == 10000){
562
        pulse = 1245;}
563
      else if(duration == 5000){
564
        pulse = 622;
565
        }
566
      else if(duration == 2500){
567
        pulse = 311;
568
        }
569
      else if(duration == 1250){
570
        pulse = 156;
571
        }
572
      else if(duration == 625){
573
        pulse = 78;
574
        }
575
      else{
576
        uC_Command = "Unzulässige Werte";
577
        }
578
    }
579
      
580
    else if (note.equals("E2")){
581
      period = 1101;
582
      if(duration == 10000){
583
        pulse = 1319;}
584
      else if(duration == 5000){
585
        pulse = 659;
586
        }
587
      else if(duration == 2500){
588
        pulse = 330;
589
        }
590
      else if(duration == 1250){
591
        pulse = 165;
592
        }
593
      else if(duration == 625){
594
        pulse = 82;
595
        }
596
      else{
597
        uC_Command = "Unzulässige Werte";
598
        }
599
    }
600
    
601
    else if (note.equals("F2")){
602
      period = 954;
603
      if(duration == 10000){
604
        pulse = 1397;}
605
      else if(duration == 5000){
606
        pulse = 698;
607
        }
608
      else if(duration == 2500){
609
        pulse = 349;
610
        }
611
      else if(duration == 1250){
612
        pulse = 175;
613
        }
614
      else if(duration == 625){
615
        pulse = 87;
616
        }
617
      else{
618
        uC_Command = "Unzulässige Werte";
619
        }
620
    }
621
    
622
    else if (note.equals("#F2")){
623
      period = 901;
624
      if(duration == 10000){
625
        pulse = 1480;}
626
      else if(duration == 5000){
627
        pulse = 740;
628
        }
629
      else if(duration == 2500){
630
        pulse = 370;
631
        }
632
      else if(duration == 1250){
633
        pulse = 185;
634
        }
635
      else if(duration == 625){
636
        pulse = 92;
637
        }
638
      else{
639
        uC_Command = "Unzulässige Werte";
640
        }
641
    }
642
    
643
    else if (note.equals("G2")){
644
      period = 850;
645
      if(duration == 10000){
646
        pulse = 1568;}
647
      else if(duration == 5000){
648
        pulse = 784;
649
        }
650
      else if(duration == 2500){
651
        pulse = 392;
652
        }
653
      else if(duration == 1250){
654
        pulse = 196;
655
        }
656
      else if(duration == 625){
657
        pulse = 98;
658
        }
659
      else{
660
        uC_Command = "Unzulässige Werte";
661
        }
662
    }
663
    
664
    else if (note.equals("#G2")){
665
      period = 803;
666
      if(duration == 10000){
667
        pulse = 1661;}
668
      else if(duration == 5000){
669
        pulse = 831;
670
        }
671
      else if(duration == 2500){
672
        pulse = 415;
673
        }
674
      else if(duration == 1250){
675
        pulse = 208;
676
        }
677
      else if(duration == 625){
678
        pulse = 104;
679
        }
680
      else{
681
        uC_Command = "Unzulässige Werte";
682
        }
683
    }
684
      
685
    else if (note.equals("A2")){
686
      period = 758;
687
      if(duration == 10000){
688
        pulse = 1720;}
689
      else if(duration == 5000){
690
        pulse = 880;
691
        }
692
      else if(duration == 2500){
693
        pulse = 440;
694
        }
695
      else if(duration == 1250){
696
        pulse = 220;
697
        }
698
      else if(duration == 625){
699
        pulse = 110;
700
        }
701
      else{
702
        uC_Command = "Unzulässige Werte";
703
        }
704
    }  
705
      
706
    else if (note.equals("#A2")){
707
      period = 715;
708
      if(duration == 10000){
709
        pulse = 1865;}
710
      else if(duration == 5000){
711
        pulse = 932;
712
        }
713
      else if(duration == 2500){
714
        pulse = 466;
715
        }
716
      else if(duration == 1250){
717
        pulse = 233;
718
        }
719
      else if(duration == 625){
720
        pulse = 117;
721
        }
722
      else{
723
        uC_Command = "Unzulässige Werte";
724
        }
725
    }
726
    
727
    else if (note.equals("B2")){
728
      period = 675;
729
      if(duration == 10000){
730
        pulse = 1976;}
731
      else if(duration == 5000){
732
        pulse = 988;
733
        }
734
      else if(duration == 2500){
735
        pulse = 494;
736
        }
737
      else if(duration == 1250){
738
        pulse = 247;
739
        }
740
      else if(duration == 625){
741
        pulse = 124;
742
        }
743
      else{
744
        uC_Command = "Unzulässige Werte";
745
        }
746
    }
747
    
748
    else if (note.equals("C3")){
749
      period = 637;
750
      if(duration == 10000){
751
        pulse = 2093;}
752
      else if(duration == 5000){
753
        pulse = 1047;
754
        }
755
      else if(duration == 2500){
756
        pulse = 523;
757
        }
758
      else if(duration == 1250){
759
        pulse = 263;
760
        }
761
      else if(duration == 625){
762
        pulse = 131;
763
        }
764
      else{
765
        uC_Command = "Unzulässige Werte";
766
        }
767
    }
768
    
769
    else if (note.equals("#C3")){
770
      period = 601;
771
      if(duration == 10000){
772
        pulse = 2218;}
773
      else if(duration == 5000){
774
        pulse = 1109;
775
        }
776
      else if(duration == 2500){
777
        pulse = 554;
778
        }
779
      else if(duration == 1250){
780
        pulse = 277;
781
        }
782
      else if(duration == 625){
783
        pulse = 139;
784
        }
785
      else{
786
        uC_Command = "Unzulässige Werte";
787
        }
788
    }
789
    
790
    else if (note.equals("D3")){
791
      period = 566;
792
      if(duration == 10000){
793
        pulse = 2350;}
794
      else if(duration == 5000){
795
        pulse = 1175;
796
        }
797
      else if(duration == 2500){
798
        pulse = 587;
799
        }
800
      else if(duration == 1250){
801
        pulse = 294;
802
        }
803
      else if(duration == 625){
804
        pulse = 147;
805
        }
806
      else{
807
        uC_Command = "Unzulässige Werte";
808
        }
809
    }
810
    
811
    else if (note.equals("#D3")){
812
      period = 536;
813
      if(duration == 10000){
814
        pulse = 2490;}
815
      else if(duration == 5000){
816
        pulse = 1245;
817
        }
818
      else if(duration == 2500){
819
        pulse = 622;
820
        }
821
      else if(duration == 1250){
822
        pulse = 311;
823
        }
824
      else if(duration == 625){
825
        pulse = 156;
826
        }
827
      else{
828
        uC_Command = "Unzulässige Werte";
829
        }
830
    }
831
    
832
    else if (note.equals("E3")){
833
      period = 483;
834
      if(duration == 10000){
835
        pulse = 2638;}
836
      else if(duration == 5000){
837
        pulse = 1319;
838
        }
839
      else if(duration == 2500){
840
        pulse = 659;
841
        }
842
      else if(duration == 1250){
843
        pulse = 330;
844
        }
845
      else if(duration == 625){
846
        pulse = 165;
847
        }
848
      else{
849
        uC_Command = "Unzulässige Werte";
850
        }
851
    }
852
    
853
    else if (note.equals("F3")){
854
      period = 477;
855
      if(duration == 10000){
856
        pulse = 2794;}
857
      else if(duration == 5000){
858
        pulse = 1397;
859
        }
860
      else if(duration == 2500){
861
        pulse = 698;
862
        }
863
      else if(duration == 1250){
864
        pulse = 349;
865
        }
866
      else if(duration == 625){
867
        pulse = 175;
868
        }
869
      else{
870
        uC_Command = "Unzulässige Werte";
871
        }
872
    }
873
    
874
    else if (note.equals("#F3")){
875
      period = 450;
876
      if(duration == 10000){
877
        pulse = 2960;}
878
      else if(duration == 5000){
879
        pulse = 1480;
880
        }
881
      else if(duration == 2500){
882
        pulse = 740;
883
        }
884
      else if(duration == 1250){
885
        pulse = 370;
886
        }
887
      else if(duration == 625){
888
        pulse = 185;
889
        }
890
      else{
891
        uC_Command = "Unzulässige Werte";
892
        }
893
    }
894
    
895
    else if (note.equals("G3")){
896
      period = 425;
897
      if(duration == 10000){
898
        pulse = 3136;}
899
      else if(duration == 5000){
900
        pulse = 1568;
901
        }
902
      else if(duration == 2500){
903
        pulse = 784;
904
        }
905
      else if(duration == 1250){
906
        pulse = 392;
907
        }
908
      else if(duration ==625){
909
        pulse = 196;
910
        }
911
      else{
912
        uC_Command = "Unzulässige Werte";
913
        }
914
    }
915
    
916
    else if (note.equals("#G3")){
917
      period = 401;
918
      if(duration == 10000){
919
        pulse = 3322;}
920
      else if(duration == 5000){
921
        pulse = 1661;
922
        }
923
      else if(duration == 2500){
924
        pulse = 831;
925
        }
926
      else if(duration == 1250){
927
        pulse = 415;
928
        }
929
      else if(duration == 625){
930
        pulse = 208;
931
        }
932
      else{
933
        uC_Command = "Unzulässige Werte";
934
        }
935
    }
936
    
937
    else if (note.equals("A3")){
938
      period = 388;
939
      if(duration == 10000){
940
        pulse = 3440;}
941
      else if(duration == 5000){
942
        pulse = 1720;
943
        }
944
      else if(duration == 2500){
945
        pulse = 880;
946
        }
947
      else if(duration == 1250){
948
        pulse = 440;
949
        }
950
      else if(duration == 625){
951
        pulse = 220;
952
        }
953
      else{
954
        uC_Command = "Unzulässige Werte";
955
        }
956
    }
957
    
958
    else if (note.equals("#A3")){
959
      period = 358;
960
      if(duration == 10000){
961
        pulse = 3730;}
962
      else if(duration == 5000){
963
        pulse = 1865;
964
        }
965
      else if(duration == 2500){
966
        pulse = 932;
967
        }
968
      else if(duration == 1250){
969
        pulse = 466;
970
        }
971
      else if(duration == 625){
972
        pulse = 233;
973
        }
974
      else{
975
        uC_Command = "Unzulässige Werte";
976
        }
977
    }
978
    
979
    else if (note.equals("B3")){
980
      period = 337;
981
      if(duration == 10000){
982
        pulse = 3952;}
983
      else if(duration == 5000){
984
        pulse = 1976;
985
        }
986
      else if(duration == 2500){
987
        pulse = 988;
988
        }
989
      else if(duration == 1250){
990
        pulse = 494;
991
        }
992
      else if(duration == 625){
993
        pulse = 247;
994
        }
995
      else{
996
        uC_Command = "Unzulässige Werte";
997
        }
998
    }
999
    
1000
    else{
1001
      uC_Command = "Unzulässige Werte";
1002
      }    
1003
  if (uC_Command.equals("Unzulässige Werte")){
1004
    uC_Command = uC_Command + "           ";
1005
    return uC_Command;
1006
  }
1007
  else{
1008
    uC_Command = uC_Command + pulse + " , " + period;
1009
    return uC_Command; 
1010
  } 
1011
}
1012
}
Die Tabelle stammt von 
http://www.mcselec.com/index.php?option=com_content&task=view&id=221&Item 
id=57

: Bearbeitet durch User
von Kindergärtner (Gast)


Lesenswert?

Cool, das erste was man am Code sieht ist...
Florian H. schrieb:
> @SuppressWarnings("deprecation")

Und diese unendlich lange Kette an else-if's, hast du die auch 
generiert? Vielleicht in Turbo Pascal? Sowas geht doch wesentlich 
schöner, kürzer, übersichtlicher - und auch noch effizienter mit sowas 
wie java.util.Map oder einfach nur Lookup-Arrays...

Zu beiden Programmen - dem Java-Code und dem Bascom-Code - kann man 
sagen:
Es ist selten eine gute Idee, Daten (in deinem Fall die Bascom-Toncodes 
in Java, und die Musikstücke in Bascom-Code) als Code zu speichern. Oft 
erhält man mehr Flexibilität, Effizienz, Übersichtlichkeit indem man die 
Daten in den vorhandenen Datenstrukturen der Sprache - Arrays, Maps, 
Listen, Trees etc. etc. - speichert, und diese mit Programmlogik 
durchgeht und verarbeitet.

von Florian H. (florian_h14)


Lesenswert?

Ich wiederhole NOCHMALS:
1. Beitrag
1. richtiges Java-Programm
Erst ein halbes Jahr Java gelernt
Und außerdem nicht an Effizienz und sonstigem interessiert wenn es um 
eine stupide Soundspielerei geht bei der nichts sonderlich Präzises von 
nöten ist. Es ist und bleibt einfach ein Langeweile-Projekt

von Kindergärtner (Gast)


Lesenswert?

Florian H. schrieb:
> Erst ein halbes Jahr Java gelernt
Ja ist ja schön... Aber wenn du was hier im Forum so postest musst du 
halt mit Kritik rechnen. Freu dich doch dass du hier noch was lernen 
kannst.

von Bastler (Gast)


Lesenswert?

Hallo Florian,
Gerade wenn du erst 0,5 Java-Jahre hinter dir hast, dann setzt dich mit 
dem Inhalt obiger Kritik auseinander. Die Form ist natürlich 
Geschmacksache. Ich finde aber auch, daß dein Java-Stil unter zuviel 
(Einfachst-)Basic zu leiden scheint ;-)
Und ich wage mal zu behaupten, daß Tonhöhe, Dauer, periode und duration 
in einer mathematischer Abhängigkeit zueinander stehen, die sich in 
Java-Code ausdrücken läßt.

von Karl H. (kbuchegg)


Lesenswert?

Florian H. schrieb:
> Ich wiederhole NOCHMALS:
> 1. Beitrag
> 1. richtiges Java-Programm
> Erst ein halbes Jahr Java gelernt

Ist schon ok.
Aber auch nach einem halben Jahr sollte man wissen, was ein Array ist 
und wie man sich aus Charactern einen Inde xso aufebereitet, dass man 
dann zb. mit einem Wert, der sich aus 'A' und '1' ergibt, in dieses 
Array gehen kann und von dort den im Sound Befehl einzustellenden Wert 
erhält.


> Und außerdem nicht an Effizienz und sonstigem interessiert wenn es um
> eine stupide Soundspielerei geht bei der nichts sonderlich Präzises von
> nöten ist. Es ist und bleibt einfach ein Langeweile-Projekt

Darum gehts doch gar nicht.
Du argumentierst jetzt gerade damit, dass du die Fläche eines Rechtescks 
mit den Kantenlängen 3 Meter und 5 Meter so ausrechnest
1
   area = 0;
2
3
   area = area + 3;
4
   area = area + 3;
5
   area = area + 3;
6
   area = area + 3;
7
   area = area + 3;

die 5 Additionen sind deshalb im Code, weil das Rechteck ja die Abmasse 
3 mal 5 hatte, daher addierst du die 3 5-mal auf.

Das ist für diesen Fall ok, aber wenn du genauer darüber nachdenkst, 
bringt dich das nicht weiter. Denn eine Fläche berechnet man eben besser 
nicht auf diese Art sondern als
1
   area = 3 * 5;
denn das funktioniert dann eben auch für andere Zahlen. Mal ganz davon 
abgesehen, dass die Additionsmethode bei einem Grundstück mit dem 
Abmassen 83 Meter mal 98 Meter schon ausartet.

Die Voraussetzung ist dafür, dass man weiß was eine Multiplikation ist 
und das sie in dieser Aufgabenstellung angebracht ist.

Bei dir ist das nicht anders. Du hast dir eine Menge Arbeit mit einer 
riesigen if-then-else Leiter gemacht ohne über Alterntaiven 
nachzudenken. Ob das jetzt aus Unwissenheit geschah, oder ob du nicht 
daran gedacht hast, weiß ich nicht. Aber nach einem halben Jahr hätte 
ich gesagt, sollte man eigentlich schon wissen was ein Array ist und 
sollte in der Lage sein, einfache Character-Auswertung und darauf 
basierende Berechnungen machen zu können.

Nimm es als Ansporn, deine Programmier-Fähigkeiten noch zu verbessern. 
Um beim Beispiel zu bleiben: bisher konntest du nur addieren. Jetzt 
lernst du eben noch, wie man multipliziert. Ist ja kein Beinbruch. Deine 
Funktion 'Convert' lässt sich mit einer anderen Methode, die zb auf 
Tabellen in einem Array beruht, auf 1/10 der jetzigen Länge einkürzen 
OHNE dabei an Klarheit zu verlieren.

: Bearbeitet durch User
von lmao (Gast)


Lesenswert?

Was für ein dummes Programm

von Paul Baumann (Gast)


Lesenswert?

@Florian

Für mich ist das Programm nützlich ;ich danke Dir für die 
Veröffentlichung.

Halte es mit Udo Lindenberg:

...Und ich mach´ mein Ding
egal, was die ander´n sagen
Ich geh´ meinen Weg
ob grade, ob schräg
das ist egal
Ich mach´ mein Ding
egal, was die ander´n labern
Was die Schwachmaten einem so raten
das ist egal
Ich mach´ mein Ding

MfG Paul

von Karl H. (kbuchegg)


Lesenswert?

Bastler schrieb:

> Und ich wage mal zu behaupten, daß Tonhöhe, Dauer, periode und duration
> in einer mathematischer Abhängigkeit zueinander stehen, die sich in
> Java-Code ausdrücken läßt.

Ist es.
Die Frequenz eines Tones verdoppelt sich von einer Oktave zu nächsten.
Der Frequenzunterschied zweier benachbarter Töne ist die 12-te Wurzel 
aus 2.

Kennt man also die Frequenz des untersten Tones, dann ist es in 
leichtes, die Frequenz jedes beliebigen Tones auf einer temperierten 
Tonleiter auszurechnen, sofern man nur weiß, wieviele Töne er vom ersten 
frequenzbekannten Ton 'entfernt' ist.

: Bearbeitet durch User
von Karl H. (kbuchegg)


Lesenswert?

Paul Baumann schrieb:

> Was die Schwachmaten einem so raten
> das ist egal
> Ich mach´ mein Ding


Paul.
Damit disqualifizierst du dich selbst.
Denn was du hier letzten Endes von dir gibst, ist nichts anderes als die 
poetische Umschreibung von: ich brauch mich nicht weiterbilden und 
dazulernen - denn mit meinem Hammer kann ich alle Reparaturen ausführen.

von Paul Baumann (Gast)


Lesenswert?

Karl-Heinz schrieb:
>Damit disqualifizierst du dich selbst.

Mach Dir mal um meine Qualifikation keine Gedanken.

Das gibt es doch gar nicht! Hier taucht ein neuer Nutzer auf und wird
gleich demontiert. Ich sage es mal rundheraus: So etwas KOTZT mich 
maximal
an.

:-((

Ab dafür...

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.