Commits

Trammell Hudson  committed f592bea

Zero bits works!

  • Participants
  • Parent commits 8ce537b

Comments (0)

Files changed (1)

 	}
 
 	// 0 bits ramp down to zero amplitude and then back up
-	for (int16_t i = 0 ; i < bit_width/2 ; i++)
+	for (int16_t i = 0 ; i < 1024 ; i++)
 	{
 		int16_t s = (uint16_t) sin_table[phase++ & 127];
 		// Shift it to the center of the waveform
 		s -= 16;
 		// scale it linearly
-		s = (s * ((bit_width/2) - i)) >> 11;
+		s = (s * (1024 - i)) >> 10;
 		// Shift it back to the DC offset
 		s += 16;
 		uint8_t spin = 28;
 	phase = (phase + 64) & 127;
 
 	// And ramp up down to zero amplitude and then back up
-	for (int16_t i = 0 ; i < bit_width/2 ; i++)
+	for (int16_t i = 0 ; i < 1024 ; i++)
 	{
 		int16_t s = (uint16_t) sin_table[phase++ & 127];
 		// Shift it to the center of the waveform
 		s -= 16;
 		// scale it linearly
-		s = (s * i) >> 11;
+		s = (s * i) >> 10;
 		// Shift it back to the DC offset
 		s += 16;
 
 		while(spin--)
 			PORTB = s;
 	}
+
+	// And now constant amplitude to round it out
+	for (int16_t i = 0 ; i < bit_width - 1024 * 2 ; i++)
+	{
+		uint8_t s = sin_table[phase++ & 127];
+		uint8_t spin = 32;
+		while(spin--)
+			PORTB = s;
+	}
 }
 
 
 		output_bit(bit);
 	}
 
-	// We've sent one zero bit already; send the last zero bit too
+	// Mark the end ofthe word with two zeros
+	output_bit(0);
 	output_bit(0);
 }