Japan would not have surrendered before the loss of Manchuria. When they lost it, they lost their largest army (the Kwantung Army) as well as their only remaining resource base. In addition, the war cabinet was vociferously against ending the war without some kind of victory. In spite of the fact that many Japanese were in favour of accepting the Allied surrender offers, the War Cabinet, which was composed of the only people in Japan with the power to end the war, was only going to accept a surrender with certain conditions attached. To that end, they continued to talk to the Soviets, trying to get the US led Allies to accept a surrender that included conditions like:
-no occupying armies on the Japanese home islands
-no war crimes tribunal
-the Emperor was not to be deposed, tried, or lose his status of a living god
-the Japanese Armed Forces were not to be disarmed.
Needless to say, these conditions were not acceptable to the US or the UK, and they were rejected out of hand. In spite of these rejections, peace feelers were often sent to the US and British governments. This went on with no change even after the first bomb was dropped. In fact, when compared to the fire bombings of Tokyo and Dresden, the Hiroshma bombing was considered to be quite tame.
All of this changed with the Soviet declaration of war, and the subsequent loss of Manchuria. Suddenly the Japanese were faced with the possibility of a Russian invasion from the north, and a US-UK-Canadian invasion from the south. They no longer had an army to defend themselves, and they no longer had the resources to build one. At this point, the manuvering began, with some members of the war cabinet killing themselves, and they were replaced by moderates. The second bomb was dropped, and the new cabinet signalled its intention to surrender to the Emperor, but there was a palace coup during which the militarists tried to keep the moderates from sending the surrender request to the Emperor. That coup was barely fought off, and in the end, the moderates had their way. But the timing of the surrender had very little to do with the atomic bomb, and everything to do with the realization that the war was lost when the Russians invaded Manchuria.